MyBatis Plus——分页插件【PaginationInnerInterceptor】
生活随笔
收集整理的這篇文章主要介紹了
MyBatis Plus——分页插件【PaginationInnerInterceptor】
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
官方文檔
https://mp.baomidou.com/guide/interceptor-pagination.html
示例工程
👉?mybatis-plus-sample-pagination
DEMO
1、啟用分頁插件
@Configuration public class CustomMyBatisPlusConfig {/*** 分頁插件,一緩和二緩遵循mybatis的規(guī)則*/@Beanpublic MybatisPlusInterceptor mybatisPlusInterceptor() {MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);// 設(shè)置請(qǐng)求的頁面大于最大頁后操作, true調(diào)回到首頁,false 繼續(xù)請(qǐng)求 默認(rèn)false// paginationInnerInterceptor.setOverflow(false);// 設(shè)置最大單頁限制數(shù)量,默認(rèn) 500 條,-1 不受限制// paginationInnerInterceptor.setMaxLimit(500L);interceptor.addInnerInterceptor(paginationInnerInterceptor);return interceptor;} }2、測試分頁查詢
@Test public void testSelectPage(){//構(gòu)建分頁條件第二頁每頁顯示3條Page<User> page=new Page<>(2,3);//使用分頁條件查詢,不使用其他條件userMapper.selectPage(page, null);//獲取分頁后查詢出的記錄List<User> records = page.getRecords();records.forEach(System.out::println);System.out.println("是否有下一頁:"+page.hasNext());System.out.println("是否有上一頁:"+page.hasPrevious());System.out.println("總記錄數(shù):"+page.getTotal()); }?
參考文章
https://www.jianshu.com/p/18f5c5881653?
https://shentuzhigang.blog.csdn.net/article/details/113818594
總結(jié)
以上是生活随笔為你收集整理的MyBatis Plus——分页插件【PaginationInnerInterceptor】的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Spring Cloud——基于Open
- 下一篇: MyBatis Plus——自定义配置—