mybatis 中 if else 用法

mybaits 中没有 else 要用 chose when otherwise 代替

下面就是MyBatis中的if....else...表示方法

<choose>
    <when test="">
        //...
    </when>
    <otherwise>
        //...
    </otherwise>
</choose>

 

例子

<select id="findActiveBlogLike"
     resultType="Blog">
  SELECT * FROM BLOG WHERE state = ‘ACTIVE’
  <choose>
    <when test="title != null">
      AND title like #{title}
    </when>
    <when test="author != null and author.name != null">
      AND author_name like #{author.name}
    </when>
    <otherwise>
      AND featured = 1
    </otherwise>
  </choose>
</select>

 

 

 

参考

https://mybatis.org/mybatis-3/zh/dynamic-sql.html

https://www.cnblogs.com/a8457013/p/8033263.html

 

原文地址:

https://www.cnblogs.com/poterliu/p/11582605.html

 

posted @ 2019-09-25 09:57  poterliu  阅读(61048)  评论(0编辑  收藏  举报