解决Mybatis--java.lang.IllegalArgumentException: Result Maps collection already contains value for XXX
来源:互联网 发布:foxit pdf editor mac 编辑:程序博客网 时间:2024/06/07 22:12
感谢幻灭若水的博客。
这两天因为项目需要整合Spring、struts2、mybatis三大框架,但启动的时候总出现这个错误,困扰我好久,在网上找到的答案都不是我想要的,今天终于知道原因了。
user-mapper.xml如下:
1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 3 "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 4 <mapper namespace="com.bmdc.dj.user.dao.UserDao"> 5 <resultMap type="user" id="userResult"> 6 <id property="user_id" column="USER_ID"/> 7 <result property="login_name" column="LOGIN_NAME"/> 8 <result property="real_name" column="REAL_NAME"/> 9 <result property="password" column="PASSWORD"/>10 </resultMap>11 <insert id="add" parameterType="user">12 insert into users (user_id, login_name, real_name, password)13 values(#{user_id}, #{login_name}, #{real_name}, #{password})14 </insert>15 </mapper>
其中,namespace是接口路径。
Mybatis.xml如下:
1 <?xml version="1.0" encoding="UTF-8" ?> 2 <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> 3 <configuration> 4 5 <!-- 别名 --> 6 <typeAliases> 7 <typeAlias type="com.bmdc.dj.user.domain.User" alias="user"/> 8 </typeAliases> 9 <mappers> 10 <mapper resource="com/bmdc/dj/user/dao/user-mapper.xml" /> 11 </mappers>12 </configuration>
其他配置文件都正确,我就不写了。这样就会出现 java.lang.IllegalArgumentException: Result Maps collection already contains value for XXX这个错误。
解决办法是:删除Mybatis.xml中的<mappers>标签所有内容。因为如果user-mapper.xml与namespace的接口在同一路径下,就不需要在mybaits.xml中再进行配置了。
修改后的Mybatis.xml如下:
1 <?xml version="1.0" encoding="UTF-8" ?>2 <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">3 <configuration>4 5 <!-- 别名 -->6 <typeAliases>7 <typeAlias type="com.bmdc.dj.user.domain.User" alias="user"/>8 </typeAliases>9 </configuration>
搞定!
0 0
- 解决Mybatis--java.lang.IllegalArgumentException: Result Maps collection already contains value for XXX
- java.lang.IllegalArgumentException: Result Maps collection already contains value for
- Mybatis异常-Result Maps collection already contains value for xxx
- java.lang.IllegalArgumentException: Result Maps collection already contains value for ciis.zht.model
- java.lang.IllegalArgumentException: Result Maps collection already contains value for com.mapper.AaM
- Caused by: java.lang.IllegalArgumentException: Result Maps collection already contains value for com
- Result Maps collection already contains value for XXX
- Result Maps collection already contains value for “XXX”问题解决
- 异常:java.lang.IllegalArgumentException: Result Maps collection already contains ...
- Spring集成Mybatis错误Result Maps collection already contains value for XXX
- MyBatis报错:Result Maps collection already contains value for .....
- mybatis报错Result Maps collection already contains value for
- Mybatis错误:Result Maps collection already contains value for ***
- mybatis result maps collection already contains value
- Result Maps collection already contains value for **
- Result Maps collection already contains value for
- Result Maps collection already contains value for ***
- Result Maps collection already contains value for
- PHP中spl_autoload_register函数的用法
- Using Redis with Node.js
- TextLine 与 buttonMode
- Windows环境下搭建机器学习玩flappy bird(1)
- js 自动缩放图片居中
- 解决Mybatis--java.lang.IllegalArgumentException: Result Maps collection already contains value for XXX
- 归并排序
- Android圆形头像(1)
- Swift3.0 单例模式实现的几种方法-Dispatch_Once
- linux usleep函数参数溢出
- GitHub上完整的iOS-App源码
- 地图动态标绘--B/S应用(二)
- Android 圆形头像(2)
- Java嵌套类(Nested Classes)总结