错误原因:
为添加处理器MyMetaObjectHandler
public class MyMetaObjectHandler implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
// 保存对象时候,获取createTime属性值;如果属性值为NULL,才进行填充
Object createTime = this.getFieldValByName("createTime", metaObject);
if (Objects.isNull(createTime)) {
// 填充
this.setFieldValByName("createTime",new Date(),metaObject);
}
}
@Override
public void updateFill(MetaObject metaObject) {
Object createTime = this.getFieldValByName("updateTime", metaObject);
if (Objects.isNull(createTime)) {
// 填充
this.setFieldValByName("updateTime",new Date(),metaObject);
}
}
}
自动更新处理步骤:
步骤一:create_time,update_time添加注解
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
@TableField(fill = FieldFill.UPDATE)
private LocalDateTime updateTime;
步骤二:添加处理器类
public class MyMetaObjectHandler implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
// 保存对象时候,获取createTime属性值;如果属性值为NULL,才进行填充
Object createTime = this.getFieldValByName("createTime", metaObject);
if (Objects.isNull(createTime)) {
// 填充
this.setFieldValByName("createTime",new Date(),metaObject);
}
}
@Override
public void updateFill(MetaObject metaObject) {
Object createTime = this.getFieldValByName("updateTime", metaObject);
if (Objects.isNull(createTime)) {
// 填充
this.setFieldValByName("updateTime",new Date(),metaObject);
}
}
}