在使用mapper.xml编写sql语句的时候,我们经常会使用到比较符号,此时不可以像往常一样直接进行使用,需要进行转义,转义参考规则如:
< | <= | > | >= | & | ’ | " |
---|---|---|---|---|---|---|
< | <= | > | >= | & | ' | " |
例如常见的时间比较:
错误写法
<select id="select" parameterType="xxx" resultMap="xxx">
select
distinct
<include refid="Base_Column_List" />
from xxx
<where>
<if test="createDate != null">
create_date <= #{createDate}
</if>
</where>
</select>
正确写法
<select id="select" parameterType="xxx" resultMap="xxx">
select
distinct
<include refid="Base_Column_List" />
from xxx
<where>
<if test="createDate != null">
create_date <= #{createDate}
</if>
</where>
</select>