在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为空,则不会拼接这一条件。


原文地址: https://www.cveoy.top/t/topic/cw0w 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录