mybatis的if判断

在mybatis框架中进行参数非空或者字符串比较判断时:

<if test = " mnyType == '1' "> 因为mybatis是用OGNL表达式解析的,在OGNL表达式中 ‘1’ 会被解析成字符串,又因为Java是强类型的,char和string会导致不相等,所以 if 标签中的SQL不会被解析。

因此单个字符要写到双引号里面或者使用 .toString() 才可以,比如正确的写法如下

<if test = "mnyType == '1'.toString() " 或者<if test = ' mnyType == "1" '>

猜你喜欢

转载自www.cnblogs.com/afeng-chen/p/12617685.html