Mybatis Mapper中的if-else使用


方法一:一般用法

select * from orcl_test t
<where>
  <if test="query == 0">
    and t.status = 1 
  </if>
  <if test="query != 0">
    and t.status NOT IN (2,3,4)
  </if>
  and t.delete_flag = 1
</where>

方法二:使用choose標簽代替if-else。

select * from orcl_test t
<where>
  <choose>
    <when test="query == 0">
      and t.status = 1
    </when>
    <otherwise>
      and t.status IN (2,3,4)
    </otherwise>
  </choose>
  and t.delete_flag = 1
</where>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM