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>

 

posted @ 2021-06-07 09:20  hi_echo  阅读(2459)  评论(0编辑  收藏  举报