Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Column注解onUpdateValue 指定值 进行更新 #334

Open
jiaqing250 opened this issue May 10, 2024 · 0 comments
Open

@Column注解onUpdateValue 指定值 进行更新 #334

jiaqing250 opened this issue May 10, 2024 · 0 comments

Comments

@jiaqing250
Copy link

版本:MyBatis Flex v1.8.2

在Activity实体的updateDate字段上使用@column注解的onInsertValue和onUpdateValue属性,导致在执行更新操作时无法手动设置该字段的值。

但是某些情况下,更新数据时需要指定数据,目前官网没有参考案例
以下是我的Activity实体类代码:

@Data
public class Activity {

    @Id
    private Long id;

    @Column(onInsertValue = "now()")
    @Schema(description = "创建时间")
    private Date createDate;

    @Column(onInsertValue = "now()", onUpdateValue = "now()")
    @Schema(description = "更新时间")
    private Date updateDate;

     
}

在执行更新操作时,我尝试手动设置updateDate的值:

Activity activity = new Activity();
activity.setId(1L);
activity.setUpdateDate(DateUtil.parse("2024-5-10 11:00:00")); // 手动设置更新时间
mapper.update(activity);

但是,执行的SQL语句没有使用我手动设置的值,而是使用了数据库的当前时间:

update activity set update_date=now() where id=1;
为了绕过限制,我不得不使用db工具编写复杂代码:

Db.updateByQuery(ActivityTableDef.ACTIVITY.getTableName(),
        new Row().set(ActivityTableDef.ACTIVITY.UPDATE_DATE, DateUtil.parse("2024-5-10 11:00:00").toString()),
        QueryWrapper.create()
                .eq(Activity::getId, 1L)
        );

期望: 希望能提供一个简单的写法,在执行更新操作时,SQL语句应使用我手动设置的updateDate值。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant