MP的分页插件

@Configuration
public class MPConfig {
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        //创建mybatisplus拦截器
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        //向拦截器中添加分页插件
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
}

MP实现分页

//测试类内
        //两个参数——当前页页码,每页信息条数
        Page<User> page = new Page<>(2,3);
        //两个参数——分页对象,条件构造器
        userMapper.selectPage(page, null);//因为我对所有的查询所以条件构造器为null——返回值还为page
        //获取当前页数据
        List<User> records = page.getRecords();
        System.out.println(records);
        //获取总记录数
        long total = page.getTotal();
        System.out.println(total);
        //获取总页数
        long pages = page.getPages();
        System.out.println(pages);
        //是否有下一页
        System.out.println(page.hasNext());
        //是否有上一页
        System.out.println(page.hasPrevious());