分页查询

1)注册分页插件(@Configuration)

    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }

2) 使用

    @Test
    void testPage(){
        Page<User> page = new Page<>(1,1); //分页(当前页,每页大小)
        userMapper.selectPage(page, null);
        page.getRecords().forEach(System.out::println); // 获取查询到的数据
        System.out.println(page.getCurrent());//获取当前页
        System.out.println(page.getPages());//获取总页数
        System.out.println(page.getSize());//获取每页显示的记录数
        System.out.println(page.getTotal()); // 获取总记录数

        System.out.println(page.hasNext());//判断是否存在下一页
        System.out.println(page.hasPrevious()); // 判断是否存在上一页
    }

 

posted @ 2021-02-28 18:32  樱花葬礼  阅读(62)  评论(0)    收藏  举报