MyBatis Plus自带分页插件,只要简单的配置即可实现分页功能
配置类中添加@Bean配置
/** * 分页插件 */ @Bean public PaginationInterceptor paginationInterceptor() { return new PaginationInterceptor(); }
@Test public void testSelectPage() { Page<User> page = new Page(1,3); Page<User> userPage = userMapper.selectPage(page, null); //返回对象得到分页所有数据 long pages = userPage.getPages(); //总页数 long current = userPage.getCurrent(); //当前页 List<User> records = userPage.getRecords(); //查询数据集合 long total = userPage.getTotal(); //总记录数 boolean hasNext = userPage.hasNext(); //下一页 boolean hasPrevious = userPage.hasPrevious(); //上一页 System.out.println(pages); System.out.println(current); System.out.println(records); System.out.println(total); System.out.println(hasNext); System.out.println(hasPrevious); }