0
点赞
收藏
分享

微信扫一扫

【MyBatis】由Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允许有内容。[引发的系列惨案]



文章目录

  • ​​报错连环案​​
  • ​​案件一​​
  • ​​案件二​​
  • ​​案件三​​
  • ​​案件四​​
  • ​​案件总结​​

报错连环案

【MyBatis】由Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允许有内容。[引发的系列惨案]_mybatis

案件一

  • java.io.FileNotFoundException: d:axis.log (系统找不到指定的路径。)
  • Exception in thread “main” org.apache.ibatis.exceptions.PersistenceException:
    Error building SqlSession.
    The error may exist in com/zyx/core/day1/dao
    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: 1; columnNumber: 1; 前言中不允许有内容。
  • 【MyBatis】由Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允许有内容。[引发的系列惨案]_apache_02

  • 仔细检查了一下,问题出现在了log4j日志的配置文件中
  • 【MyBatis】由Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允许有内容。[引发的系列惨案]_返回顶部_03

  • 这里的log4j.appender.LOGFILE.File配置的是日志文件路径,我的盘中没有D盘,同时路径的格式也有问题。

修改了之后,发现第一个路径问题解决了,但是Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允许有内容。依然存在,上网搜了一下,说是大多数记事本工具(Emedit等)默认是以utf-8 BOM方式,会在文件中加入BOM头,导致错误,然后我使用notpad++更改了之后还是不对。

【MyBatis】由Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允许有内容。[引发的系列惨案]_apache_04


点开日志文件,发现编码是 gbk?!而且也修改不了~

【MyBatis】由Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允许有内容。[引发的系列惨案]_返回顶部_05


​​返回顶部​​

案件二

又看了其他的报错,The error may exist in com/zyx/core/day1/dao,这是MyBatis中的映射文件配置路径,写错了?

【MyBatis】由Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允许有内容。[引发的系列惨案]_apache_06


修改后:

【MyBatis】由Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允许有内容。[引发的系列惨案]_sql_07


好家伙,又报了新的错!!!

​​返回顶部​​

案件三

【MyBatis】由Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允许有内容。[引发的系列惨案]_sql_08


Exception in thread “main” org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.zyx.core.day1.dao.IUserDao.findAll​​

【MyBatis】由Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允许有内容。[引发的系列惨案]_返回顶部_09


修改后,去掉方法后的括号 ()

【MyBatis】由Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允许有内容。[引发的系列惨案]_返回顶部_10


​​返回顶部​​

案件四

紧接着又报了错:Cause: org.apache.ibatis.executor.ExecutorException: A query was run and no Result Maps were found for the Mapped Statement 'com.zyx.core.day1.dao.IUserDao.findAll'. It's likely that neither a Result Type nor a Result Map was specified.

这个错主要是因为我们,只通过整个流程使用MyBatis去进行数据库的操作,但是并没有指定查到结果后的返回类型,在代码中我们是要查询所有,同时创建了实体类,所以这里我们最终的返回类型就应该是实体类类型;通过resultType属性设置返回类型的全路径类。

【MyBatis】由Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允许有内容。[引发的系列惨案]_mybatis_11


最终运行结果:

【MyBatis】由Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允许有内容。[引发的系列惨案]_mybatis_12

案件总结

整理一下所有报错,wy~

  • 1.​java.io.FileNotFoundException: d:axis.log (系统找不到指定的路径。) 配置日志路径的时候要注意本地存在~
  • 2.​Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允许有内容。 很有可能是UTF-8 BOM 格式的问题,显然这里我的不是~,但值得注意!!!
  • 3.​Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: Error building SqlSession.The error may exist in com/zyx/core/day1/dao​​
    ​​Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration.​​
    ​​Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. 这个错是由于映射配置文件路径没写全导致后面解析配置文件创建SqlSessionFactory工厂失败,注意路径要一直写到具体的配置文件
  • 4.​Exception in thread “main” org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.zyx.core.day1.dao.IUserDao.findAll 这个错是由于在配置具体映射文件的时候,配置增强dao层的方法时多添加了() 引起的,注意不需要!!!
  • 5.​Cause: org.apache.ibatis.executor.ExecutorException: A query was run and no Result Maps were found for the Mapped Statement 'com.zyx.core.day1.dao.IUserDao.findAll'. It's likely that neither a Result Type nor a Result Map was specified. 这个错主要是因为我们,只通过整个流程使用MyBatis去进行数据库的操作,但是并没有指定查到结果后的返回类型,在代码中我们是要查询所有,同时创建了实体类,所以这里我们最终的返回类型就应该是实体类类型;通过resultType属性设置返回类型的全路径类。

【MyBatis】由Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允许有内容。[引发的系列惨案]_apache_13

​​返回顶部​​


举报

相关推荐

0 条评论