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>

  这是需求文档原图


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM