mybatis映射程序文件转义字符



在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>

最新更新