mybatis中怎么判断一个值是什么

e5dbe2c8bb5bf9490ba13c35ab33795
除了if判断6次。还有什么办法简洁点的

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

数据库直接case when。后台逻辑就不用去判断了

2 Likes

可以建个枚举类,对值进行转换