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

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐