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