Mybatis报错——Mapped Statements collection already contains value for 。。。
程序员文章站
2022-03-08 15:55:41
...
Mybatis报错——Mapped Statements collection already contains value for com.mapper.EmployeeMapperPlus.getEmpByIdDe
异常如下:
org.apache.ibatis.exceptions.PersistenceException:
### Error building SqlSession.
### The error may exist in com/mapper/EmployeeMapperPlus.xml
### The error occurred while processing mapper_resultMap[MyEmp_disc]_discriminator_case[1]
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML.
Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.mapper.EmployeeMapperPlus.getEmpByIdDe
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)
... 31 more
报错分析:
关键是这两句:
Error parsing Mapper XML
意思是:Mapper.xml映射文件解析错误
Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.mapper.EmployeeMapperPlus.getEmpByIdDe
意思是:映射声明集合中已经包含方法
com.mapper.EmployeeMapperPlus.getEmpByIdDe
报错原因:
Mapper映射文件中SQL标签的id属性,是与Mapper接口中的方法一一对应的。
上面错误顾名思义就是SQL标签中有 id 重复的标签。故而报出映射声明集合中已经包含某方法(Mapped Statements collection already contains value for )
如下代码,第一个标签与第三个标签id相同就会报这个异常。
<mapper namespace="com.mapper.EmployeeMapperPlus">
<select id="getEmpByIdDe" resultMap="MySinpleEmp">
select * from tbl_employee where id = #{id}
</select>
<select id="getEmpByIdStep" resultMap="MyEmpByStep">
select * from tbl_employee where id = #{id}
</select>
<select id="getEmpByIdDe" resultMap="MyEmp_disc">
select * from tbl_employee where id = #{id}
</select>
</mapper>
错误解决:
查找根据报错提示的映射文件名和方法名,查找是否有id属性重复的SQL标签。
上一篇: 刷题 - 数组中只出现1次的两个数
推荐阅读
-
使用mybatis报错【Result Maps collection already contains value for ...BaseResultMap】的解决方法
-
moven 部署Sping与mybatis时,Mapped Statements collection does not contain value for Xxxxxxxx
-
Mapped Statements collection already contains value for xxx
-
Mybatis:Mapped Statements collection does not contain value for
-
[email protected]使用报错:Mapped Statements collection does not contain value for XXX
-
mybatis错误 Mapped Statements collection does not contain value for
-
Mybatis报错—— Mapped Statements collection does not contain value for com.mapper.DepartmentMapper
-
Mapped Statements collection already contains value for ……
-
Mapped Statements collection already contains value for
-
解决报错:Mapped Statements collection already contains value for...