使用MybatisPlus实现对数据库分页查询
使用selectPage方法
public List<ProductInspectionForm> selectPage(int page,int limit) {
IPage iPage = new Page(page,limit);
formMapper.selectPage(iPage,null);
return iPage.getRecords();
}
光使用方法不行,还需要用到MybatisPlus拦截器
@Configuration
public class MybatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor(){
MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
return mybatisPlusInterceptor;
}
}
测试结果如下
@Test
void testPro(){
IPage page = new Page(0,2);
productInspectionFormMapper.selectPage(page,null);
System.out.println(page.getRecords());
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/ff5a5553cb7c4aa3996e8992508cdd4a.png)