mybatis and,or复合查询

末蓝、 2022-05-14 04:50 328阅读 0赞

要查询的sql:

  1. select * from user where name = ? and (age=? or city=?);

方法1:不使用Example查询
直接在usermapper.xml中修改sql

方法2:使用Example查询
sql可转换成

  1. select * from user where (name = ? and age=?) or (name=? and city=?);

然后使用Example查询

  1. UserExample example=new UserExample();
  2. example.or().orAgeLike("%"+searchParam+"%").andNameEqualTo(userName);
  3. example.or().orCityLike("%"+searchParam+"%").andNameEqualTo(userName);

发表评论

表情:
评论列表 (有 0 条评论,328人围观)

还没有评论,来说两句吧...

相关阅读

    相关 ElasticSearch 复合查询

    使用bool查询 接收以下参数: must:文档必须匹配这些条件才能被包含进来。 must \_not:文档必须不匹配这些条件才能被包含进来。 should:如

    相关 【MySQL】复合查询

    前面我们讲解的mysql表的查询都是对一张表进行查询,在实际开发中这远远不够。 1.多表查询 实际开发中往往数据来自不同的表,所以需要多表查询。本节我们用一个简单的公司