报错连环案

在这里插入图片描述

案件一

  • 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; 前言中不允许有内容。

    在这里插入图片描述
    仔细检查了一下,问题出现在了log4j日志的配置文件中
    在这里插入图片描述
    这里的log4j.appender.LOGFILE.File配置的是日志文件路径,我的盘中没有D盘,同时路径的格式也有问题。

修改了之后,发现第一个路径问题解决了,但是Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 前言中不允许有内容。依然存在,上网搜了一下,说是大多数记事本工具(Emedit等)默认是以utf-8 BOM方式,会在文件中加入BOM头,导致错误,然后我使用notpad++更改了之后还是不对。
在这里插入图片描述
点开日志文件,发现编码是 gbk?!而且也修改不了~
在这里插入图片描述
返回顶部


案件二

又看了其他的报错,The error may exist in com/zyx/core/day1/dao,这是MyBatis中的映射文件配置路径,写错了?
在这里插入图片描述
修改后:
在这里插入图片描述
好家伙,又报了新的错!!!

返回顶部


案件三

在这里插入图片描述
Exception in thread “main” org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.zyx.core.day1.dao.IUserDao.findAll
在这里插入图片描述
修改后,去掉方法后的括号 ()
在这里插入图片描述
返回顶部


案件四

紧接着又报了错: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属性设置返回类型的全路径类。
在这里插入图片描述
最终运行结果:
在这里插入图片描述


案件总结

整理一下所有报错,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属性设置返回类型的全路径类。

在这里插入图片描述

返回顶部


Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐