您的位置:首页 > 移动开发

java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for org.fkit

2017-03-24 15:49 781 查看
报错信息:

Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for org.fkit.mapper.StudentMapper.selectStudent
### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for org.fkit.mapper.StudentMapper.selectStudent
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.selectList(DefaultSqlSession.java:98)
at org.fkit.test.SelectStudentTest.main(SelectStudentTest.java:12)
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for org.fkit.mapper.StudentMapper.selectStudent
at 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

报错来源:在mybatis中进行查询时,运行代码报错误,错误的意思时:映射语句没有org.fkit.mapper.StudentMapper.selectStudent
在我的mybatis-config.xml中配置信息是: <mappers>
<mapper resource="org/fkit/mapper/UserMapper.xml"/>
</mappers>并没有配置StudentMapper的映射,所以在启动程序时,mybatis不知道去哪里找持久化类的映射文件了
正确的配置是: <mappers>
<mapper resource="org/fkit/mapper/UserMapper.xml"/>
<mapper resource="org/fkit/mapper/StudentMapper.xml"/>
</mappers>遇到这样的错误,不仅仅是映射文件没有配置,总的来说:
1、mapper.xml中没有加入namespace 

2、mapper.xml中的方法和接口mapper的方法不对应 

3、mapper.xml没有加入到mybatis-config.xml中(即总的配置文件),例外:配置了mapper文件的包路径的除外 

4、mapper.xml文件名和所写的mapper名称不相同。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐