- mybatis and,or复合查询
要查询的sql:
select * from user where name = ? and (age=? or city=?);
方法1:不使用Example查询直接在usermapper.xml中修改sql
方法2:使用Example查询sql可转换成
select * from user where (name = ? and age=?) or (name=? and city=?);
然后使用Example查询
UserExample example=new UserExample();
example.or().orAgeLike("%"+searchParam+"%").andNameEqualTo(userName);
example.or().orCityLike("%"+searchParam+"%").andNameEqualTo(userName);
参考:https://blog.csdn.net/cuyun11/article/details/82343381