【備忘】mybatis的條件判斷用


mybatis並沒有if..else,在mybatis的sql mapper文件中,條件判斷要用choose..when..otherwise。
 
<choose>
  <when test="status == 'PROCES' or status == 'PENDNG'"> and batcol.status in('PROCES','PENDNG')</when>
  <when test="status == 'PREAUD'"> and batcol.status = '--'</when>
  <otherwise> and batcol.status = #{status,jdbcType=CHAR}</otherwise>
</choose>
 
<if test="status != null and status != 'all'" >
  <choose>
    <when test="status == 'PROCES' or status == 'PENDNG'"> and batcol.status in('PROCES','PENDNG')</when>
    <when test="status == 'PREAUD'"> and batcol.status = '--'</when>
    <otherwise> and batcol.status = #{status,jdbcType=CHAR}</otherwise>
  </choose>

</if>
 
        
choose為一個整體,
when表示if ,(when可重復,即實現if..else if..else if..
otherwise表示else。
注意: test里的等號用==,而不是=。


免責聲明!

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



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