PaginationInterceptor
確保你已經(jīng)在 MyBatis-Plus 的配置中添加了分頁插件。如果你使用的是 Spring Boot珊皿,通常是在 MybatisPlusConfig 類中添加分頁插件的 Bean。
@Configuration
public class MybatisPlusConfig {
@Bean
public PaginationInnerInterceptor paginationInnerInterceptor() {
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
return paginationInnerInterceptor;
}
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
mybatisPlusInterceptor.setInterceptors(Collections.singletonList(paginationInnerInterceptor()));
return mybatisPlusInterceptor;
}
@Bean
public EasySqlInjector easySqlInjector(){
return new EasySqlInjector();
}
}
EasySqlInjector :自定義的批量插入
public class EasySqlInjector extends DefaultSqlInjector {
/**
* sql注入器
* add批量插入InsertBatchSomeColumn方法
* 此方法比saveBatch效率更高,一次io
*/
@Override
public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {
List<AbstractMethod> methodList = super.getMethodList(mapperClass, tableInfo);
methodList.add(new InsertBatchSomeColumn(i -> i.getFieldFill() != FieldFill.UPDATE));
methodList.add(new InsertBatchSomeColumn());
return methodList;
}
}