MyBatis框架中使用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>