这种问题在xml在SQL语句中的where约束中直接写>或<号是会报错 ,这就要求我们来进行特殊处理。
其实很简单,我们只需作如下转义替换即可避免上述的错误:。
| < | <= | > | >= | & | ' | " |
|
< |
<= |
> |
>= |
& |
' |
" |
例如常见的时间比较:
错误写法
<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>
本文详细介绍了在XML文件的SQL语句中如何正确处理特殊字符,如大于号、小于号等,以避免语法错误。通过实例展示了将这些符号进行转义的方法,确保SQL语句在MyBatis或其他XML配置的环境中能够正常运行。
3156

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



