mybatis动态sql判断参数是指定字符串
可以使用Mybatis的if标签来判断参数是否是指定字符串,例如:
<select id="getUserByName" resultType="User">
select * from user
<where>
<if test="name != null and name == 'admin'">
and name = #{name}
</if>
</where>
</select>
上述例子中,if标签的test属性中判断了参数name是否不为空且是否等于字符串"admin",如果满足条件,则拼接SQL语句中的and name = #{name},否则不拼接。这样就可以动态判断参数是否是指定字符串了。
原文地址: https://www.cveoy.top/t/topic/cw0W 著作权归作者所有。请勿转载和采集!