一、Springboot 配置分页插件
@Configuration public class PageConfig { /*分页插件*/ @Bean public MybatisPlusInterceptor mybatisPlusInterceptor() { MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2)); return interceptor; } }
二、代码测试
@Test public void testPage(){ //设置分页参数 Page<User> page = new Page<>(1, 5); //查询数据库操作
userMapper.selectPage(page, null); //获取分页数据 List<User> list = page.getRecords(); list.forEach(System.out::println); System.out.println("当前页:"+page.getCurrent()); System.out.println("每页显示的条数:"+page.getSize()); System.out.println("总记录数:"+page.getTotal()); System.out.println("总页数:"+page.getPages()); System.out.println("是否有上一页:"+page.hasPrevious()); System.out.println("是否有下一页:"+page.hasNext()); }
三、测试结果如下
UserDO(id=1, name=小, sex=男, password=123, status=1) UserDO(id=2, name=名, sex=女, password=123, status=0) UserDO(id=3, name=个, sex=男, password=123, status=1) UserDO(id=4, name=xiao, sex=女, password=5555, status=0) UserDO(id=6, name=小, sex=女, password=778999897, status=0) 当前页:1 每页显示的条数:5 总记录数:22 总页数:5 是否有上一页:false 是否有下一页:true
标签:插件,MybatisPlus,System,id,类篇,println,page,out From: https://www.cnblogs.com/Life-QX/p/17207273.html