0
点赞
收藏
分享

微信扫一扫

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

Mhhao 2023-06-16 阅读 39

下面就是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>

举报

相关推荐

0 条评论