Wondercease

浙ICP备2022017321号

mybatis 中 if else 用法

mybatis 中 if else 用法 mybatis中文网

在 mybaits 中,只有 if 标签,并没有 else 标签,可以使用 chose when otherwise 代替。

<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>

发表评论

您的电子邮箱地址不会被公开。