先看Mybatis-Plus官网中对这两个关键字用法的介绍
数据库文件:
链接:https://pan.baidu.com/s/1KzY32Jq0srDQU9m-a-YtBQ?pwd=rsdg
提取码:rsdg
表数据:
比如我们想查age等于23并且school_id等于300的
sql语句为:select * FROM student where age='23' or school_id='300'
最直接的方法:
List<Student> students = studentMapper
.selectList(Wrappers.lambdaQuery(Student.class)
.eq(Student::getAge, "23")
.or()
.eq(Student::getSchoolId,300));
也可以用下面的方法
用mybatis-plus则为:
List<Student> students = studentMapper.selectList(Wrappers.lambdaQuery(Student.class) .eq(Student::getAge, "23") .or(s -> s.eq(Student::getSchoolId, 300)));
比如我们想查 age等于25或者姓张的同学
sql语句:select * FROM student where age='25' or `name` LIKE '张%'
用mybatis-plus最直接的方法
List<Student> students = studentMapper .selectList(Wrappers.lambdaQuery(Student.class) .eq(Student::getAge, "25") .or() .likeRight(Student::getName, "张"));
也可以用以下方法
List<Student> students = studentMapper .selectList(Wrappers.lambdaQuery(Student.class) .eq(Student::getAge, "25") .or(s->s.likeRight(Student::getName,"张")));