- 分页操作需要设定分页对象IPage
@Test
void testPage(){
IPage page = new Page(1,2);
bookDao.selectPage(page,null);
System.out.println("数据总条数:"+page.getTotal());
System.out.println("当前页:"+page.getCurrent());
System.out.println("当前页条数:"+page.getSize());
System.out.println("总页数"+page.getPages());
System.out.println("数据:"+page.getRecords());
}
- 使用拦截器
在Springboot中设置配置类并且创建拦截方法
@Configuration
public class MyConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
//1、定义拦截器
MybatisPlusInterceptor mpInterceptor = new MybatisPlusInterceptor();
//2、添加具体拦截器
mpInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
return mpInterceptor;
}
}