1. 在config文件里面新增分页插件
//分页插件
@Bean
public PaginationInterceptor paginationInterceptor() {
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
// 设置请求的页面大于最大页后操作, true调回到首页,false 继续请求 默认false
// paginationInterceptor.setOverflow(false);
// 设置最大单页限制数量,默认 500 条,-1 不受限制
// paginationInterceptor.setLimit(500);
// 开启 count 的 join 优化,只针对部分 left join
// paginationInterceptor.setCountSqlParser(new JsqlParserCountOptimize(true));
return paginationInterceptor;
}
2. 在代码里使用分页插件
@Test
void testPageQuery(){
Page<User> page = new Page<>(3,5);
//wrapper 条件构造器,模糊查询,排序,多表查询,子查询等
userMapper.selectPage(page,null);
List<User> users = page.getRecords();
users.forEach(System.out::println);
System.out.println(page.getCurrent());
System.out.println(page.getOrders());
System.out.println(page.getRecords());
System.out.println(page.getSize());
System.out.println(page.getTotal());
System.out.println(page.hasNext());
System.out.println(page.hasPrevious());
}
@Test
void testPageQuery2(){
Page<Map<String,Object>> page = new Page<>(3,5);
//wrapper 条件构造器,模糊查询,排序,多表查询,子查询等
IPage<Map<String,Object>> mapIPage = userMapper.selectMapsPage(page,null);
mapIPage.getRecords().forEach(System.out::println);
System.out.println(page.getCurrent());
System.out.println(page.getOrders());
System.out.println(page.getRecords());
System.out.println(page.getSize());
System.out.println(page.getTotal());
System.out.println(page.hasNext());
System.out.println(page.hasPrevious());
网友评论