LambdaQueryWrapper用法
LambdaQueryWrapper 与QueryWrapper查询类似,不过使用的是Lambda语法。
文章共430字 · 阅读需要大约2分钟
一键AI生成摘要,助你高效阅读
问答
·
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);
}
更多推荐
已为社区贡献16条内容
所有评论(0)