- <if test="type=='y'">
- and status = 0
- </if>
当传入的type的值为y的时候,if判断内的sql也不会执行,应改为:
- <if test='type=="y"'>
- and status = 0
- </if>
或者改成:
<if test="type eq 'y'.toString()"> and status = 0 </if>
就可以执行了,这样"y"解析出来是一个字符串,两者相等!
二:
<if test="id != null and id != '' ">
id = #{id}
</if>
如果id类型为int 当id=0时 这个判断不会进入,这种写法只适用于 id 类型为字符串。
改为:
<if (test="id != null and id != '') or test==0">
id = #{id}
</if>
或者:
<if test="id != null">
id = #{id}
</if>
本文详细介绍了SQL语句中使用条件判断时常见的问题及解决策略,包括类型转换、null值判断的正确方式,并通过具体实例展示了如何避免误判导致的查询效率降低。

1959

被折叠的 条评论
为什么被折叠?



