LambdaQueryWrapper 与QueryWrapper查询类似,不过使用的是Lambda语法

 public Result queryById(Long id) {
        LambdaQueryWrapper<Comment> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Comment::getArticleId, id);
//        1. 其中Comment::getArticleId的意思就相当于:
//        1.1 实例化一个Comment对象
//        Comment comment = new comment;
//        1.2 调用对象Comment的get方法,这里调用的是getArticleId:
//        comment.getArticleId();
//        2.eq方法相当于赋值“=”
//        即将ArticleId的值为参数id,注意此时使用的是get方法而不是set方法
        queryWrapper.eq(Comment::getLevel, 1);
        queryWrapper.orderByDesc(Comment::getCreateDate);
        List<Comment> comments = commentMapper.selectList(queryWrapper);
        List<CommentVo> commentVoList = copyList(comments);
        return Result.success(commentVoList);
    }

在这里插入图片描述

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐