【MyBatis】使用if进行字符串比较导致的bug?

BUG 的情况如下:

  <if test="a !=null and a='1'.toString()">
    and a = #{a}
  </if>

这样写导致的就是不管a传什么值,最后都会拼接上 and a = 1 这一段SQL。

原因就是 a = '1'.toString() 而不是 a == '1'.toString().

在OGNL表达式里是可以进行再赋值的,真是新大陆!!!~~~

posted @ 2021-11-17 22:43  rongbu2  阅读(62)  评论(0)    收藏  举报