MyBatis 动态 SQL 判断字符串内容:if 标签示例
在 MyBatis 中,可以使用 if 标签来判断是否为某个字符串。示例如下:
<select id="selectUserByName" parameterType="String" resultType="User">
SELECT * FROM user
WHERE
<if test="name != null and name != ''">
name = #{name}
</if>
</select>
在上面的示例中,如果传入的 name 参数不为空,则会拼接上 name = #{name} 这一条件。如果 name 为空,则不会拼接这一条件。
原文地址: http://www.cveoy.top/t/topic/nwSK 著作权归作者所有。请勿转载和采集!