1、如果没有自定义SqlSessionFactory类,加配置类即可
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor(){
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
//添加分页插件
PaginationInnerInterceptor pageInterceptor = new PaginationInnerInterceptor();
//设置请求的页面大于最大页的操作,true调回首页,false继续请求,默认是false
pageInterceptor.setOverflow(false);
//单页分页的条数限制,默认五限制
pageInterceptor.setMaxLimit(500L);
//设置数据库类型
pageInterceptor.setDbType(DbType.MYSQL);
interceptor.addInnerInterceptor(pageInterceptor);
return interceptor;
}
2、如果自定义了SqlSessionFactory类,在配置中加分页插件。
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
//添加分页插件
PaginationInnerInterceptor pageInterceptor = new PaginationInnerInterceptor();
pageInterceptor.setDbType(DbType.MYSQL);
interceptor.addInnerInterceptor(pageInterceptor);
sessionFactory.setPlugins(interceptor);
完美解决: