• 使用分页前先引用分页的拦截器
    在配置类用引用mybatisplus的分页
@Configuration
public class MPConfig {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
        return interceptor;
    }
}

  • 编写测试类
@Test
    void testGetPage(){
        IPage page = new Page(1,5);

        bookDao.selectPage(page ,null);
        //查询的数据集合
        System.out.println(page.getRecords());
        //查询的分页数量
        System.out.println(page.getPages());
        //当前所在分页
        System.out.println(page.getCurrent());
        //每页的大小数量
        System.out.println(page.getSize());
        //所有数据数量
        System.out.println(page.getTotal());
    }