Mybatis Plus 分页插件
本文最后更新于:2024年9月8日 晚上
Mybatis Plus 分页插件
配置插件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| @Configuration @MapperScan("com.example.*.mapper*") public class MybatisPlusConfig {
@Bean public PaginationInterceptor paginationInterceptor() { PaginationInterceptor paginationInterceptor = new PaginationInterceptor(); paginationInterceptor.setOverflow(false); paginationInterceptor.setLimit(500); paginationInterceptor.setCountSqlParser(new JsqlParserCountOptimize(true)); return paginationInterceptor; } }
|
使用分页
1 2 3 4 5 6 7 8
| @Test public void testPage(){
Page<User> page = new Page<>(2,5); userMapper.selectPage(page,null); page.getRecords().forEach(System.out::println); System.out.println(page.getTotal()); }
|
Page(int currentpage,int pageSize)
currentPage
:当前页。
pageSize
:页面大小。