第一步:在springboot启动类中注册mybatis-plus 拦截器,在拦截器中添加分页功能。
@Bean public MybatisPlusInterceptor plusInterceptor(){ MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor(); mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); return mybatisPlusInterceptor; }
第二步:分页的使用。
@Test public void testPage(){ Page<User> page = new Page<>(2,3); userMapper.selectPage(page,null); long current = page.getCurrent(); long size = page.getSize(); List<User> records = page.getRecords(); long total = page.getTotal(); System.out.println("records:" + records); }