In normal development, we often use
<if test="topicType != null and topicType != ''"> AND a.topic_type = #{topicType} </if>
This form of judgment, when I use "==" judgment, there is a strange problem
code show as below:
<if test="createBy != null and topicType == '1'"> AND a.create_by = #{createBy.id} </if>
When I meet these two conditions, the query file still cannot be appended.
Change it to:
<if test="createBy != null and topicType == '1'.toString()"> AND a.create_by = #{createBy.id} </if>
or
<if test='createBy != null and topicType == "1"'> AND a.create_by = #{createBy.id} </if>
After that, my query conditions can be used normally.
Mybatis is parsed with OGNL expressions. In OGNL expressions, '1' will be parsed as characters, java is strongly typed, char and a string will cause inequality, so the sql in the if tag will not be parsed as a character. Parse. A single character needs to be written in double quotes or use .toString()!