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

报错信息:

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名称不相同。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值