本文主要是介绍Mybatis:Mapped Statements collection does not contain value for,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
bug:使用Mybatis时,报错;
Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for mycom.mapping.SampleMapper.selectByPrimaryKey
### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for mycom.mapping.SampleMapper.selectByPrimaryKeyat 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 mycom.test.mybatis.test.MybatisTest.main(MybatisTest.java:43)
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for mycom.mapping.SampleMapper.selectByPrimaryKeyat org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:797)at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:631)at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:624)at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:107)... 3 more
原因:以下映射sql的标识字符串和Samplemapper.xml中的namespace()不一致;之前都是手写的namespace,命名的时候,使用的是mapper.xml的目录,这次是用工具自动生成的mapper.xml,namespace命名是用的dao目录;
String statement2 = "mycom.mapping.SampleMapper.selectByPrimaryKey";//映射sql的标识字符串Sample result = session.selectOne(statement2, 2);System.out.println(result);
这篇关于Mybatis:Mapped Statements collection does not contain value for的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!