Type interface com.pastor.mapper.CardMapper is not known to the MapperRegistry. 解决方法
出错环境 :
在MyBatis环境下以注解的方法来实现对MySQL数据库一对一的操作
解决方法 :
在MyBatisConfig.xml中给CardMapper接口注册
<mappers>
<mapper class="com.pastor.mapper.CardMapper" />
</mappers>
如果不把相对应的另外一个接口注册将会报以下错误
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.pastor.mapper.PersonMapper.selectById
### The error may exist in com/pastor/mapper/CardMapper.java (best guess)
### The error may involve com.pastor.mapper.CardMapper.selectAll
### The error occurred while handling results
### SQL: SELECT * FROM card
### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.pastor.mapper.PersonMapper.selectById
解决方法 :
把所引用的接口都进行注册
<mappers>
<mapper class="com.pastor.mapper.CardMapper" />
<mapper class="com.pastor.mapper.PersonMapper" />
</mappers>
本文介绍在MyBatis环境下,通过注解方式操作MySQL数据库时遇到的Mapper未注册问题及其解决方法。主要讨论了如何在配置文件中正确注册Mapper接口,以避免运行时出现PersistenceException异常。
1万+

被折叠的 条评论
为什么被折叠?



