Mybatis Mapper中的if-else使用

时间:2021-06-07 12:10:23   收藏:0   阅读:32

方法一:一般用法

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>

 

原文:https://www.cnblogs.com/ningcc/p/14857507.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!