第一种
用转移字符把“>”和“<”替换掉
<if test='strSettMonth!=null and strSettMonth!=\"\" '>
and sett_month >= #{strSettMonth,jdbcType=VARCHAR}
</if>
<if test='endSettMonth!=null and endSettMonth!=\"\" '>
and sett_month <= #{endSettMonth,jdbcType=VARCHAR}
</if>"
sett_month是varchar类型;
附:XML转义字符
< | < | 小于号 |
> | > | 大于号 |
& | & | 和 |
' | ’ | 单引号 |
" | " | 双引号 |
第二种
因为这是xml格式的,所以不允许出现类似">"这样的字符,但是可以使用<![CDATA[ ]]>符号进行说明,将此类符号不进行解析
mapper文件示例代码
<if test="startTime != null ">
AND <![CDATA[ order_date >= #{startTime,jdbcType=DATE} ]]>
</if>
<if test="endTime != null ">
AND <![CDATA[ order_date <= #{endTime,jdbcType=DATE} ]]>
</if>