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没有正确匹配的情况。如以下代码:
Mybatis报错:org.apache.ibatis.builder.IncompleteElementException: Could not find result map

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

解决方法:
将select标签的resultMap属性标注为对应resultMap标签的id,如以下代码:
Mybatis报错:org.apache.ibatis.builder.IncompleteElementException: Could not find result map
保证蓝框内容一致,即可正常运行。

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二者选其一,不要一起用。