在xml中写sql语句时,(<)小于号往往不会被解析转义,此时就需要用特定给方法解决
一:使用特殊字符转义
在限定的日期范围内查询时:>=startTime,<=endTime
> > 大于号 (可以被解析)
< < 小于号 (重点)
<if test="endTime!= null and endTime!= ''">
AND date_format(CREATETIME,'%Y-%m-%d %H:%i:%s') <= #{endTime,jdbcType=VARCHAR}
</if>
二:使用<![CDATA[ ]]>符号
<![CDATA[ ]]>符号内的内容不会被解析<if test="endTime != null and endTime !=''">
<![CDATA[ AND date_format(CREATETIME,'%Y-%m-%d %H:%i:%s') <= #{endTime,jdbcType=VARCHAR} ]]>
</if>
或者
<if test="endTime != null and endTime !=''">
AND date_format(CREATETIME,'%Y-%m-%d %H:%i:%s') <![CDATA[ <= ]]> #{endTime,jdbcType=VARCHAR}
</if>