除了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
可以建个枚举类,对值进行转换