平时开发中咱们常常用到java
<if test="topicType != null and topicType != ''"> AND a.topic_type = #{topicType} </if>
这种形式的判断,当我用“==”判断时出现了一个奇怪的问题sql
代码以下:mybatis
<if test="createBy != null and topicType == '1'"> AND a.create_by = #{createBy.id} </if>
当我这两个条件都知足时这个查询提件依然不能追加。开发
将其改成:string
<if test="createBy != null and topicType == '1'.toString()"> AND a.create_by = #{createBy.id} </if>
或者test
<if test='createBy != null and topicType == "1"'> AND a.create_by = #{createBy.id} </if>
以后,个人查询条件就能够正常使用了。查询
mybatis是用OGNL表达式来解析的,在OGNL的表达式中,’1’会被解析成字符,java是强类型的,char 和 一个string 会致使不等,因此if标签中的sql不会被解析。 单个的字符要写到双引号里面或者使用.toString()才行!top