mybatis在处理or连接多条件查找时的方法

最近公司分配了一个任务,类似于多条件查询,价格分不同的区间组,如0-300000,300000-1000000.。。。。。。
在拼接时发现了一个问题,当第一个条件不成立时,会出现and ( or 条件2 or 条件3 or 条件4), 这样就会出问题,
所以思考良久,得出以下解决方案:(所有条件都放在list里,用1,2,3,4来判断)
<if test="list3  != null and list3.size()>0">
   and ( 1 !=1
   <foreach collection="list3" item="item" index="index">
      <if test="item  != null and item = 1">
         or INVESTMENT_ESTIMATION_ between 0 and 300000
      </if>
      <if test="item  != null and item = 2">
               or INVESTMENT_ESTIMATION_ between 300000 and 1000000
      </if>
      <if test="item  != null and item = 3">
         or INVESTMENT_ESTIMATION_ between 1000000 and 5000000
      </if>
      <if test="item  != null and item = 4">
         or INVESTMENT_ESTIMATION_ > 5000000
      </if>
   </foreach>
   )
</if>

  这是需求文档原图

posted @ 2019-03-04 10:48  回眸一下  阅读(9020)  评论(0编辑  收藏  举报