- 首页 > it技术 > >
Mybatis-plus自动填充字段
@Configuration
@Component
public class MybatisMetaHandler implements MetaObjectHandler {
@Bean
public OptimisticLockerInterceptorOptimisticLockerInterceptor() {
return new OptimisticLockerInterceptor();
}@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}@Bean
public ConfigurationCustomizer configurationCustomizer() {
return configuration -> configuration.setUseDeprecatedExecutor(false);
}@Override
public void insertFill(MetaObject metaObject) {
this.setFieldValByName("createTime",new Date(),metaObject);
}@Override
public void updateFill(MetaObject metaObject) {
this.setFieldValByName("updateTime",new Date(),metaObject);
}
}
推荐阅读