问题mappaer中if判断语句失效
xxxMapper.xml
<if test="isRead != null and isRead == '0'.toString()">
AND IsRead=0
</if>
其中isRead为String类型,加单引号是无法解决的
mybatis是用OGNL表达式来解析的,在OGNL的表达式中,’0’会被解析成字符,java是强类型的,char 和 一个string 会导致不等,所以if标签中的sql不会被解析。
在做字符串的比较的情况下,需要将字符转为字符串类型
解决方法
1.加上 ‘0’.toString()
<if test="isRead != null and isRead == '0'.toString()">
AND IsRead=0
</if>
2.里面的单引号使用转义符号 "
<if test="isRead != null and isRead == "0"">
AND IsRead=0
</if>
3. 将字符 '0' 改为字符串类型“0”,外层单引号里面双引号
<if test='isRead != null and isRead == "0"'>
AND IsRead=0
</if>