自定义的@TableField,解决插入或更新失效
01 使用场景
02 配置类和扫描包
package com. ruoyi. framework. hander ;
import com. baomidou. mybatisplus. core. handlers. MetaObjectHandler ;
import org. apache. ibatis. reflection. MetaObject ;
import org. springframework. stereotype. Component ;
import java. util. Date ;
@Component
public class FieldHandler implements MetaObjectHandler {
@Override
public void insertFill ( MetaObject metaObject) {
this . setFieldValByName ( "createTime" , new Date ( ) , metaObject) ;
this . setFieldValByName ( "updateTime" , new Date ( ) , metaObject) ;
}
@Override
public void updateFill ( MetaObject metaObject) {
this . setFieldValByName ( "updateTime" , new Date ( ) , metaObject) ;
}
}
03 总结