概述
and和or的使用
案例1:where A=? and B=?
//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=?
//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=?)
//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=?)
// 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=?))
// 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的组合使用所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复