mybatis在mapper.xml文件中的大于小于等符号处理

在项目中加了个查询,没注意这个问题,结果一运行报错,说什么没法注入bean,还觉得哪错了,再往上翻debug信息发现了:debug

 Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 310; columnNumber: 15; 元素内容必须由格式正确的字符数据或标记组成。code

原来是SQL语句中用了大于小于符号:xml

<if test="type != null">
	AND INSTR(type,#{type,jdbcType=VARCHAR}) > 0
</if>

用转义符替换后正常运行:io

<if test="type != null">
	AND INSTR(type,#{type,jdbcType=VARCHAR}) &gt; 0
</if>

 

转义符class

&lt;        <        小于号
&gt;        >        大于号
&amp;        &        和
&apos;        ’        单引号
&quot;        "        双引号test

<![CDATA[ ]]>jdbc

还有种解决方案,使用<![CDATA[ ]]>符号进行说明,里面的内容将不进行解析 
 bug

<![CDATA[ AND INSTR(type,#{type,jdbcType=VARCHAR}) > 0 ]]>
相关文章
相关标签/搜索