1. 背景
以前我在使用ORM框架的时候,一般使用mybatis xml generator插件生成代码,但升级了知识库以后,我都采用另外一套jar生成苞米豆ORM为框架的crud代码,包括controller
2. 步骤
将实体类中属性数据类型为LocalDate和LocalDateTime修改成java.util.Date类型
分页配置类
java
@Configuration
public class MyBatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
PaginationInnerInterceptor paginationInnerInterceptor =
new PaginationInnerInterceptor(DbType.MYSQL); paginationInnerInterceptor.setOverflow(true);
// 指定数据库类型
interceptor.addInnerInterceptor(paginationInnerInterceptor); return interceptor;
}
}
编写自动填充配置类
库里面create_time、update_time都是用的datetime ,框架生成代码后我都修改成了Date类型
typescript
@Component
public class CommonMetaObjectHandler implements MetaObjectHandler {
/**
* 新增
* */
@Override
public void insertFill(MetaObject metaObject) {
this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());
}
/**
* 修改
* */
@Override
public void updateFill(MetaObject metaObject) {
this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());
}
}