mybatis-plus 3.3.1 日期字段填充无效,求大神指导!

zb1517583268657 发布于 05/13 20:02
阅读 323
收藏 1

Linux基金会免费官方培训及考试申请即将截止,戳这里申请!>>>

加载中
0
宇宙星星
z
zb1517583268657
你说的这两个方法我都用过,都没有! 而却3.3.1 作者提示这个方法已经过时了,3.3.0之后建议使用新的方法。
0
L1Leon
L1Leon
MetaObjectHandler实现类是不是忘加@Component注解了
0
蛋挞王子
蛋挞王子

version3.3.1

entity:


  @TableField(value = "createtime", fill = FieldFill.INSERT)
  private Date createtime;


  @TableField(value = "createby", fill = FieldFill.INSERT)
  private String createby;

  @TableField(value = "updatetime", fill = FieldFill.INSERT_UPDATE)
  private Date updatetime;

  @TableField(value = "updateby", fill = FieldFill.INSERT_UPDATE)
  private String updateby;
配置
@Slf4j
public class MetaObjectFillHandler implements MetaObjectHandler {

    protected static final String FIELD_CREATE_USER_ID = "createby";
    protected static final String FIELD_CREATE_TIME = "createtime";
    protected static final String FIELD_UPDATE_USER_ID = "updateby";
    protected static final String FIELD_UPDATE_TIME = "updatetime";

    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insert fill ....");
        this.strictInsertFill(metaObject, FIELD_CREATE_USER_ID, String.class, UserHelper.getCurrentUserId());

        this.strictInsertFill(metaObject, FIELD_CREATE_TIME, Date.class, new Date());

        this.strictInsertFill(metaObject, FIELD_UPDATE_USER_ID, String.class, UserHelper.getCurrentUserId());

        this.strictInsertFill(metaObject, FIELD_UPDATE_TIME, Date.class, new Date());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start update fill ....");
        this.strictUpdateFill(metaObject, FIELD_UPDATE_USER_ID, String.class, UserHelper.getCurrentUserId());

        this.strictUpdateFill(metaObject, FIELD_UPDATE_TIME, Date.class, new Date());
    }
}
@Bean
public MetaObjectHandler metaObjectHandler() {
    return new MetaObjectFillHandler();
}

 

使用正常

返回顶部
顶部