mybatis 映射器文件转义字符
zhengyun_ustc
阅读:26
2025-02-15 21:57:57
评论:0
在用于 sql select 语句的 mybatis 映射器文件中,我无法在 where 表达式中使用特殊字符 (<=)。例如(一个简化的选择):
<select id="selectMonday" resultType="SheetGameRec">
select ColumnName
from Table
where ColumnName <= 2
order by ColumnName;
</select>
产生以下错误
Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:
### Error building SqlSession.
### The error may exist in Mapper.xml
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper
Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: xx; columnNumber: xx; The content of elements must consist of well-formed character data or markup.
如果我将 <= 替换为 >= 或 =,映射器文件将起作用,尽管这不是我想要的选择。
我如何转义这些特殊字符。我也遇到了其他表达式(例如 & )的问题。我正在使用 mybatis 3.0.2。
谢谢。
请您参考如下方法:
您可以使用 CDATA
转义特殊字符。
<select id="selectMonday" resultType="SheetGameRec">
select ColumnName
from Table
where ColumnName <![CDATA[ <= 2 ]]>
order by ColumnName;
</select>
声明
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。