- 在需要自动填充的字段上添加注解@TableField
@ApiModelProperty(value = "创建时间")
@TableField(fill = FieldFill.INSERT)
private Date gmtCreate;
@ApiModelProperty(value = "更新时间")
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date gmtModified;
- 配置元数据处理器MetaObjectHandler
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
//在插入时需要填充的字段
@Override
public void insertFill(MetaObject metaObject) {
this.setFieldValByName("gmtCreate",new Date(),metaObject);
this.setFieldValByName("gmtModified",new Date(),metaObject);
}
//在更新时需要填充的字段
@Override
public void updateFill(MetaObject metaObject) {
this.setFieldValByName("gmtModified",new Date(),metaObject);
}
}
标签:metaObject,填充,setFieldValByName,Date,字段,mybatis,new,public
From: https://www.cnblogs.com/blog-zyx/p/16904109.html