MyBatisPlus AND OR 联合使用
程序员文章站
2024-02-20 11:21:11
...
原生的SQL:
select * from t_user where sex='male'
and ((name=ylw and age=18) or (name=dumas and age=20));
MyBatisPlus 写法:
QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
userQueryWrapper.eq("sex","male");
queryWrapper.and(wrapper ->{
wrapper.and(nameAgeQueryWrapper ->{
nameAgeQueryWrapper.or(itemWrapper ->{
itemWrapper.eq("name","ylw");
itemWrapper.eq("age",18);
});
nameAgeQueryWrapper.or(itemWrapper ->{
itemWrapper.eq("name","dumas");
itemWrapper.eq("age",20);
});
});
});
List<User> user = mapper.selectList(queryWrapper);