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

使用mybatis报错

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文件中,将 resultTyperesultMap 弄混淆。

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

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

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

          检查写的Mapper文件是不是全部返回值错误,每一个都要检查 ,希望大家以后都不要再犯这种错误 !

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

<mapper namespace="com.xxx.mapper.xxxMapper">


这个namespace引入的mapper文件要和你的mapper.xml文件对应。

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

参考文章:https://blog.csdn.net/lin_xiaofeng/article/details/79140769

猜你喜欢

转载自blog.csdn.net/qq_42402854/article/details/86589001