PersistenceException解决方法

本文介绍在MyBatis环境下,通过注解方式操作MySQL数据库时遇到的Mapper未注册问题及其解决方法。主要讨论了如何在配置文件中正确注册Mapper接口,以避免运行时出现PersistenceException异常。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值