在用于 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>
关于mybatis 映射器文件转义字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26704101/