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