分页查询

分页查询

分页插件有很多

  1. 原始的limit进行1分页
  2. pageHelper第三方插件
  3. MybatisPlus内置插件

如何使用?

配置config

//分页插件
@Bean
public PaginationInterceptor paginationInterceptor() {
    return new PaginationInterceptor();
}
  • 直接使用即可
//分页插件
@Test
public void testPage(){
    //参数一:当前页
    //参数二:页面大小
    Page<User> objectPage = new Page<>(1, 5);//第1页,5行数据
    mapper.selectPage(objectPage, null);//分页查询 条件为null
    System.out.println(objectPage.getTotal());//获取总记录数
    System.out.println(objectPage.getCurrent());//获取当前页
    objectPage.getRecords();//获取数据
    objectPage.getRecords().forEach(System.out::println);//打印输出
}
posted @ 2021-07-29 17:04  saxon宋  阅读(53)  评论(0)    收藏  举报