欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-03-24 11:37:18
...
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'xxxMapper' defined in file [D:\codes\xxx\xxx\target\classes\com\xxx\xxx\mapper\xxxMapper.class]: 
Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: 
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: 
Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: 
Factory method 'sqlSessionFactory' threw exception; 
nested exception is org.springframework.core.NestedIOException: 
Failed to parse mapping resource: 'file [D:\codes\xxx\xxx\target\classes\mybatis\xxxMapper.xml]'; 
nested exception is org.apache.ibatis.builder.BuilderException: 
Error creating document instance.  
Cause: org.xml.sax.SAXParseException; lineNumber: 134; columnNumber: 59; 元素内容必须由格式正确的字符数据或标记组成。

出现此错误的原因:Mybatis xml文件中sql语句有误,一般是特殊字符没有做处理。

Mybatis-Mapper特殊字符转换表格如下,仅供参考

符号 转移符 说明
> > 大于
< &lt; 小于
>= &gt;= 大于等于
<= &lt;= 小于等于
& &amp;
&apos; 单引号
" &quot; 双引号

或者采用 <![CDATA[]]> 装饰
例如:

id <![CDATA[>=]]> #{id}     // id>=#{id}
相关标签: java