错误写法:
<if test="promoteText != null and promoteText == '2'">
and A.promote_text is not null
</if>
<if test="promoteText != null and promoteText == '3'">
and A.promote_text is null
</if>
正确写法:
<if test="promoteText != null and promoteText != ''">
<if test="promoteText == '2'.toString() ">
and A.promote_text is not null
</if>
<if test="promoteText=='3'.toString()">
and A.promote_text is null
</if>
</if>
mybatis是用OGNL表达式来解析的,在OGNL的表达式中,’1’会被解析成字符,java是强类型的,char 和 一个string 会导致不等,所以if标签中的sql不会被解析。 单个的字符要写到双引号里面或者使用.toString()才行!