MyBatis中if里的test条件等值判断问题
原创
©著作权归作者所有:来自51CTO博客作者攻城狮Chova的原创作品,请联系作者获取转载授权,否则将追究法律责任
问题
- 在MyBatis中if中条件判断时,由于test里用了 =, 导致这个if一直处在生效的状态
<if test="lastResult != null and lastResult != '' and orderStatus = '80'">
AND p.LAST_RESULT = #{lastResult,jdbcType=VARCHAR} AND p.ORDER_STATUS = '80'
</if>
原因
-
= 是赋值符号
-
== 才是判断相等符号
- 另外,如果值为String, 需要加上toString
<if test="lastResult != null and lastResult != '' and orderStatus == '80'.toString()">
AND p.LAST_RESULT = #{lastResult,jdbcType=VARCHAR} AND p.ORDER_STATUS = '80'
</if>
总结