我是靠谱客的博主 单薄保温杯,这篇文章主要介绍MybatisPlus中and和or的组合使用,现在分享给大家,希望可以做个参考。

and和or的使用


案例1:where   A=? and B=?

复制代码
1
2
3
4
        //SELECT id,name,age,sex FROM student WHERE (name = ? AND age = ?)         List<Student> list = studentService.lambdaQuery().eq(Student::getName, "1").eq(Student::getAge, 1).list();      


案例2:where A=? or B=?

复制代码
1
2
3
4
        //SELECT id,name,age,sex FROM student WHERE (name = ? OR age = ?)         List<Student> list = studentService.lambdaQuery().eq(Student::getName, "1").or().eq(Student::getAge, 12).list();


案例3:where A=? or(C=? and D=?)

复制代码
1
2
3
4
5
6
7
8
9
        //SELECT id,name,age,sex FROM student WHERE (name = ? OR (name = ? AND age = ?))        List<Student> list =           studentService               .lambdaQuery()               .eq(Student::getName, "1")               .or(wp -> wp.eq(Student::getName, "1").eq(Student::getAge, 12))               .list();      


案例4:where (A=?andB=?)or(C=?andD=?)

复制代码
1
2
3
4
5
6
7
8
9
10
    // SELECT id,name,age,sex FROM student WHERE ((name = ? AND age = ?) OR (name = ? AND age = ?))      List<Student> list =         studentService             .lambdaQuery()             .and(wp -> wp.eq(Student::getName, "1").eq(Student::getAge, 12))             .or(wp -> wp.eq(Student::getName, "1").eq(Student::getAge, 12))             .list();    


案例5:whert  A =? or (B=? and ( C=? or D=?))

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
      // SELECT * FROM student WHERE ((name <> 1) OR (name = 1 AND (age IS NULL OR age >= 11)))     List<Student> list =         studentService             .lambdaQuery()             .and(wp -> wp.ne(Student::getName, "1"))             .or(                 wp ->                     wp.eq(Student::getName, "1")                         .and(wpp -> wpp.isNull(Student::getAge).or().ge(Student::getAge, 11)))             .list();    


 

最后

以上就是单薄保温杯最近收集整理的关于MybatisPlus中and和or的组合使用的全部内容,更多相关MybatisPlus中and和or内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部