正确写法:
<if test='parentId != null and parentId != "" and parentId != "0"'>
and
</if>
有问题写法:
<if test="parentId != null and parentId != '' and parentId != '0'">
上面的例子中,parentId的类型为String,当parentId的值为数字(数字类型的字符串)时,判断没有问题。
若parentId的值为字符,判断时则会抛出类型转换错误,具体如下:
Caused by: java.lang.NumberFormatException: For input strin
个人认为原因如下:
1.字符串的比较
必须用双引号;
2.
若是单引号OGNL表达式会进行类型转换,所以会抛出类型转换错误。
相关问题:https://www.oschina.net/question/2402835_2275480
不足之处,望大家指出,谢谢。
转载于:https://my.oschina.net/whatwhy/blog/1813033