配置完成后访问业务模块抛出Mapped Statements collection does not contain value for


2019-07-06 11:33:21,329 [main] [org.apache.ibatis.logging.LogFactory]-[DEBUG] Logging initialized using 'class org.apache.ibatis.logging.slf4j.Slf4jImpl' adapter.
2019-07-06 11:33:21,342 [main] [org.apache.ibatis.datasource.pooled.PooledDataSource]-[DEBUG] PooledDataSource forcefully closed/removed all connections.
2019-07-06 11:33:21,342 [main] [org.apache.ibatis.datasource.pooled.PooledDataSource]-[DEBUG] PooledDataSource forcefully closed/removed all connections.
2019-07-06 11:33:21,342 [main] [org.apache.ibatis.datasource.pooled.PooledDataSource]-[DEBUG] PooledDataSource forcefully closed/removed all connections.
2019-07-06 11:33:21,342 [main] [org.apache.ibatis.datasource.pooled.PooledDataSource]-[DEBUG] PooledDataSource forcefully closed/removed all connections.
Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for uUserMapper.queryById
### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for uUserMapper.queryById
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:111)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:66)
at com.itcast.b_mybatis.mybatis01.main(mybatis01.java:32)

 

网上查了出现该问题的情况可能有几种:

  • mybatis的映射文件的命令空间与接口的全限定名不一致;
  • 有可能mybatis的映射文件名字与接口的类名字不一致;
  • 还有一种情况就是接口声明的方法在映射文件里面没有。
  • 检查mapper包中的mapper.xml没有编译到targger中, 想到maven的配置文件可能有问题,排查发现,没有配置build的resources
  • 附上原文地址:https://blog.csdn.net/weimezilie/article/details/51940546

检查发现是名称不一致导致的出错:

<mapper namespace="userMapper">
 User user = sqlSession.selectOne("UserMapper.queryById", 1L);
 User user = sqlSession.selectOne("userMapper.queryById", 1L);

留下经验,以防再次出错.

分类: JAVA

发表评论

电子邮件地址不会被公开。 必填项已用*标注