报错java.lang.IllegalArgumentException: Result Maps collection does not contain value解决

                                        <p>使用mybatis报错</p>

java.lang.IllegalArgumentException: Result Maps collection does not contain value for com.xxx.mapper.xxxMapper.xxx

at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:853) ~[mybatis-3.4.0.jar:3.4.0]

at org.apache.ibatis.session.Configuration.getResultMap(Configuration.java:605) ~[mybatis-3.4.0.jar:3.4.0]

at org.apache.ibatis.builder.MapperBuilderAssistant.getStatementResultMaps(MapperBuilderAssistant.java:344)

本人总结了两点原因:

1. 在 mapper.xml 文件中,将 resultType 和 resultMap 弄混淆。

这个原因一般报错的第一行后面都会有这样一句话 org.apache.ibatis.builder.IncompleteElementException: Could not find result map com.xxx.xxx with root cause

注意:使用 resultMap 时,必须要有 <resultMap></resultMap> 标签指明 id 和返回类型以及表字段的对应关系。

如果是直接返回一个用户定义的实体类型,则要使用 resultType,弄混淆就会报错。

2. 在 mapper.xml 头部 namespace 引入错误。


<mapper namespace="com.xxx.mapper.xxxMapper">
这个 namespace 引入的 mapper 文件要和你的 mapper.xml 文件对应。

一般都是第一条原因,自己踩过的坑,希望可以帮到你。