Mybatis报错:org.apache.ibatis.builder.IncompleteElementException: Could not find result map

报错详情:
Error querying database. Cause: org.apache.ibatis.builder.IncompleteElementException: Could not find result map...
数据库查询出错,抛出IncompleteElementException异常,原因:找不着result map

报错原因:
Mybatis的Mapper.xml文件中存在resultMap没有正确匹配的情况。如以下代码:
在这里插入图片描述

其中,select标签的resultMap属性误写成了类名bean.Goods(如红框所示),运行时无法通过该属性找到对应的resultMap,所以报错。

解决方法:
将select标签的resultMap属性标注为对应resultMap标签的id,如以下代码:
在这里插入图片描述
保证蓝框内容一致,即可正常运行。

P.S. 对于老手来说,出现这个错误,大概率是手一抖,但是对于新手来说,可能是对于MyBatis不够熟悉。这里引用一下MyBatis对于resultMap这个参数的解释

resultMap:
A named reference to an external resultMap.
Result maps are the most powerful feature of MyBatis, and with a good understanding of them, many difficult mapping cases can be solved.
Use resultMap OR resultType, not both.

翻译一下

resultMap:
对外部resultMap命名的引用。
Result map是MyBatis最强大的特性,深入了解之后,可以解决很多映射难题。
在一个语句,resultMap和resultType二者选其一,不要一起用。

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值