要查询的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);
本文介绍了两种SQL查询方法:一种是在usermapper.xml中直接修改SQL语句,另一种是使用Example查询方式。通过具体的SQL语句和代码示例展示了如何实现条件查询。
4162

被折叠的 条评论
为什么被折叠?



