学习Mybatis时报错:org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession.

学习Mybatis时报错:org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession.

报错详情为;
Caused by: org.apache.ibatis.exceptions.PersistenceException:
Error building SqlSession.
Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 12; 2 字节的 UTF-8 序列的字节 2 无效。
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:64)
at com.youhs.utils.MybatisUtils.(MybatisUtils.java:23)

原因

xml文件的注释里写了中文,因此使用utf-8解码会报错。
解决方法:将xml文件的编码方式改为GBK或者UTF-8

<?xml version="1.0" encoding="UTF-8" ?>

改为:

<?xml version="1.0" encoding="GBK" ?>

可参考文章:https://blog.csdn.net/shengsummer/article/details/8934847

上一篇:SpringBoot整合MyBatis时报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not foun


下一篇:Mybatis拦截器动态修改sql语句