Page和list的区别 mybatis

先看一段代码

点击查看代码
    @Override
    public Result findUserPage(PageParam pageParam) {
        Page<SysUser> page = new Page<>(pageParam.getPageNum(), pageParam.getPageSize());
        LambdaQueryWrapper<SysUser> wrapper = new LambdaQueryWrapper<>();
        if (pageParam.getAddress()!=null){
            wrapper.like(SysUser::getAddress,pageParam.getAddress());
        }
        if (pageParam.getUsername()!=null){
            wrapper.like(SysUser::getUsername,pageParam.getUsername());
        }
        if (pageParam.getEmail()!=null) {
            wrapper.like(SysUser::getEmail,pageParam.getEmail());
        }
        wrapper.orderByAsc(SysUser::getId);
        System.err.println("==================================");
        Page<SysUser> sysUserPage = sysUserMapper.selectPage(page, wrapper);
        System.err.println("==================================");
        sysUserPage.getRecords().forEach(System.out::println);
        System.err.println("==================================");
        List<SysUser> list = sysUserPage.getRecords();
        return Result.success(sysUserPage);
    }
}
  • 下面是page输出的结果,看上面的代码可知,page和list经过转换,输出结果一样

直接输出page的结果

  • 结论: 一个是对象一个是集合,page是经过封装的
posted @ 2022-05-01 11:24  雨同我  阅读(621)  评论(0编辑  收藏  举报