项目场景开发环境描述问题描述解决方案原因分析其他可能出现的错误参考文献写在后面
项目场景最近,在跟着黑马IT的视频学习mybatis,现记录如下
开发环境描述IDEA版本:20201.1
JDK版本:jdk1.8.0_181、jdk-14.0.2、jdk-16.0.1
Maven版本:apache-maven-3.5.2
该问题出现在以上版本,并成功解决。
问题描述出现报错:Type interface com.itheima.dao.IUserDao is not known to the MapperRegistry.
解决方案核对 SqlMapConfig.xml 中信息径发现并无异常,最终发现自己的 namespace 写错了。
修改 namespace
再次运行,成功解决
原因分析一般出现 Type interface com.itheima.dao.IUserDao is not known to the MapperRegistry. 异常时,我们应该安装以下步骤进行排查:
- 检查 SqlMapConfig.xml 中有没有配置 mapper 路径检查 SqlMapConfig.xml 中 resource 指定位置是都有误检查路径中的 namespace 是否配置错误
需要注意,如果报错是org.apache.ibatis.exceptions.PersistenceException:### Error querying database. 需要根据后面的 Cause:xxx来判断错误类型
resultType 配置错误的话,会报 Cause: org.apache.ibatis.reflection.ReflectionException: Error instantiating interface com.itheima.dao.IUserDao with invalid types () or values (). Cause: java.lang.NoSuchMethodException: com.itheima.dao.IUserDao.
sql语句错误的话,会报 Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'eesy_mybatis.usr' doesn't exist 异常
参考文献1.Mybatis:Type interface com.itheima.dao.IUserDao is not known to the MapperRegistry.解决方案
写在后面欢迎随时留言讨论,知无不答!



