「MyBatis」MyBatis常用标签
# 与、非
<if test="author != null and author.name != null">
AND author_name like #{author.name}
</if>
# 判断 (if)
<select id="findActiveBlogLike" resultType="Blog">
SELECT * FROM BLOG WHERE state = ‘ACTIVE’
<if test="title != null">
AND title like #{title}
</if>
<if test="author != null and author.name != null">
AND author_name like #{author.name}
</if>
</select>
# 判断选择 (类 Switch)
从多个条件中选择一个使用
<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>
<choose>
:switch<when>
:case<otherwise>
:default
上次更新: 2022/12/31, 03:04:26