mybatis-plus、PageHelper分页插件

PageHelper:轻量级插件,无须撰写limit语句。

PageHelper.startPage(1, 10);
List userList = userMapper.getUsers();
PageInfo pageInfo = new PageInfo<>(userList);

mybatis-plus:重量级插件,无须撰写limit


service层、controller层
    public void testSelectPage() {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.gt("age", 20);
        Page page = new Page<>(1, 1);
        //根据条件查询数据
        IPage iPage = this.userMapper.selectPage(page, wrapper);
        System.out.println("数据总条数:" + iPage.getTotal());
        System.out.println("总页数:" + iPage.getPages());
        List users = iPage.getRecords();
        for (User user : users) {
            System.out.println("user = " + user);
        }
    }

 

你可能感兴趣的:(mybatis,mybatis)