Mybatis-plus3.4.0之前一直重写的PaginationInterceptor作为分页插件,但是在3.4.0以后,删除了不少类,PaginationInterceptor也不幸被删除,致使项目报错。
PaginationInterceptor类中有
红色区域已经说明使用MybatisPlusInterceptor和PaginationInnerInterceptor替代,
现将版本升级前后的代码拿出来,
升级前:
@Configuration
public class MybatisPlusConfig {
/**
* mybatis-plus分页插件<br>
* 文档:http://mp.baomidou.com<br>
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
paginationInterceptor.setDialectType("Oracle");
return paginationInterceptor;
}
}
升级后:
@Configuration
public class MybatisPlusConfig {
/**
* mybatis-plus分页插件<br>
* 文档:http://mp.baomidou.com<br>
*/
@Bean
public MybatisPlusInterceptor paginationInterceptor() {
MybatisPlusInterceptor paginationInterceptor = new MybatisPlusInterceptor();
PageInterceptorInterceptor pageInterceptor = new PageInterceptorInterceptor(DbType.ORACLE);
pageInterceptor.setOverflow(true);
pageInterceptor.setMaxLimit(500L);
paginationInterceptor.addInnerInterceptor(pageInterceptor);
paginationInterceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
return paginationInterceptor;
}
}
可以使用MybatisPlusInterceptor的setProperties方法(本地测试时没有进入这个类中,不清楚为啥)
@Configuration
public class MybatisPlusConfig {
/**
* mybatis-plus分页插件<br>
* 文档:http://mp.baomidou.com<br>
*/
@Bean
public MybatisPlusInterceptor paginationInterceptor() {
MybatisPlusInterceptor paginationInterceptor = new MybatisPlusInterceptor();
Properties properties = new Properties();
properties.setProperty("@page","com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor");
properties.setProperty("page:overflow","true");
properties.setProperty("page:dbType","Oracle");
properties.setProperty("page:maxLimit","500");
paginationInterceptor.setProperties(properties);
paginationInterceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
return paginationInterceptor;
}
}