方法一:使用转义字符
& &
< <
> >
" " (双引号)
' ' (单引号)
例子: createTime>= beginDate and createTime <= endDate
<if test="beginDate != null ">
and createTime >= #{beginDate}
</if>
<if test="endDate != null ">
and createTime <= #{endDate}
</if>
方法二:使用<![CDATA[ 特殊字符或SQL语句 ]]>
例子:
<if test="beginDate != null ">
and createTime <![CDATA[ >= ]]> #{beginDate}
</if>
<if test="endDate != null ">
and createTime <![CDATA[ <= ]]> #{endDate}
</if>
或
<if test="beginDate != null ">
and <![CDATA[ createTime >= #{beginDate} ]]>
</if>
<if test="endDate != null ">
and <![CDATA[ createTime <= #{endDate} ]]>
</if>