LambdaQueryWrapper用法简单介绍

1.层级关系
请添加图片描述
2.LambdaQueryWrapper :与QueryWrapper查询类似,不过使用的是Lambda语法。
举例如下:

package com.mszlu.blog.dao.pojo;

import lombok.Data;

@Data
public class Comment {

    private Long id;

    private String content;

    private Long createDate;

    private Long articleId;

    private Long authorId;

    private Long parentId;

    private Long toUid;

    private Integer level;
}
 
 public Result commentsByArticleId(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);
    }
 

QueryWrapper其他方法参考下图:
请添加图片描述

 
 
posted @ 2022-09-05 11:48  门罗的魔术师  阅读(5238)  评论(0)    收藏  举报