MybatiPlus 分页插件PaginationInnerInterceptor

config类引入插件

 1 //Spring boot方式
 2 @Configuration
 3 @MapperScan("com.baomidou.cloud.service.*.mapper*")
 4 public class MybatisPlusConfig {
 5     //旧版
 6     @Bean
 7     public PaginationInterceptor paginationInterceptor() {
 8         PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
 9         // 设置请求的页面大于最大页后操作, true调回到首页,false 继续请求  默认false
10         // paginationInterceptor.setOverflow(false);
11         // 设置最大单页限制数量,默认 500 条,-1 不受限制
12         // paginationInterceptor.setLimit(500);
13         // 开启 count 的 join 优化,只针对部分 left join
14         paginationInterceptor.setCountSqlParser(new JsqlParserCountOptimize(true));
15         return paginationInterceptor;
16     }
17       // 最新版
18     @Bean
19     public MybatisPlusInterceptor mybatisPlusInterceptor() {
20         MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
21         interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
22         return interceptor;
23     }
24 }

使用测试

1     PageResult<ContactMember> pageResult = new PageResult<>();
2     long current = param.getCurrent() == null ? 1 : param.getCurrent();
3     long size = param.getSize() == null ? 10 : param.getSize();
4  
5     Page<ContactMember> page = new Page<>(current, size);
6     IPage<ContactMember> contactMemberIPage = contactMemberMapper.selectPage(page, param);

原文:https://blog.csdn.net/weixin_43735255/article/details/123545461

posted @ 2022-03-31 19:39  冢本八云  阅读(1410)  评论(0编辑  收藏  举报