【备忘】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