第七题用nested的优势是什么呢,用and也能实现
/**
* 需求:(年龄小于40或邮箱不为空)并且名字为王姓
* 条件:(age<40 or email is not null) and name like '王%'
* sql:SELECT * FROM mp_user WHERE (name LIKE '王%' AND ((age < 40 OR email IS NOT NULL)))
*/
@Test
public void selectByWrapper7(){
QueryWrapper<User> queryWrapper = Wrappers.query();
queryWrapper.and(qw->qw.lt("age",40).or().isNotNull("email"))
.likeRight("name","王");
List<User> userList = userMapper.selectList(queryWrapper);
userList.forEach(System.out::println);
}
老师,我用的and也可以,为什么要用nested呢,这个方法有什么优点吗?