直接在mapper.xml中写 <小于号是会报错的,需要我们做一个替换处理。
| < | <= | > | >= | & | ’ | " |
|---|---|---|---|---|---|---|
| < | <= | > | >= | & | ' | " |
错误写法:报错
<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>

本文介绍了在MyBatis的mapper.xml文件中如何正确使用特殊字符,特别是小于号和大于号等,以避免语法错误。通过对比错误和正确的写法,帮助开发者理解XML转义字符的必要性和具体应用。
2万+

被折叠的 条评论
为什么被折叠?



