如何解决Mybatis--java.lang.IllegalArgumentException: Result Maps collection already contains value for X
程序员文章站
2024-03-09 17:30:53
这两天因为项目需要整合spring、struts2、mybatis三大框架,但启动的时候总出现这个错误,困扰我好久,在网上找到的答案都不是我想要的,今天终于知道原因了。...
这两天因为项目需要整合spring、struts2、mybatis三大框架,但启动的时候总出现这个错误,困扰我好久,在网上找到的答案都不是我想要的,今天终于知道原因了。
user-mapper.xml如下:
<?xml version="1.0" encoding="utf-8"?> <!doctype mapper public "-//mybatis.org//dtd mapper 3.0//en" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.bmdc.dj.user.dao.userdao"> <resultmap type="user" id="userresult"> <id property="user_id" column="user_id"/> <result property="login_name" column="login_name"/> <result property="real_name" column="real_name"/> <result property="password" column="password"/> </resultmap> <insert id="add" parametertype="user"> insert into users (user_id, login_name, real_name, password) values(#{user_id}, #{login_name}, #{real_name}, #{password}) </insert> </mapper>
其中,namespace是接口路径。
mybatis.xml如下:
<?xml version="1.0" encoding="utf-8" ?> <!doctype configuration public "-//mybatis.org//dtd config 3.0//en" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!-- 别名 --> <typealiases> <typealias type="com.bmdc.dj.user.domain.user" alias="user"/> </typealiases> <mappers> <mapper resource="com/bmdc/dj/user/dao/user-mapper.xml" /> </mappers> </configuration>
其他配置文件都正确,我就不写了。这样就会出现 java.lang.illegalargumentexception: result maps collection already contains value for xxx这个错误。
解决办法是:删除mybatis.xml中的<mappers>标签所有内容。因为如果user-mapper.xml与namespace的接口在同一路径下,就不需要在mybaits.xml中再进行配置了。
修改后的mybatis.xml如下:
<?xml version="1.0" encoding="utf-8" ?> <!doctype configuration public "-//mybatis.org//dtd config 3.0//en" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!-- 别名 --> <typealiases> <typealias type="com.bmdc.dj.user.domain.user" alias="user"/> </typealiases> </configuration>
以上所述是小编给大家介绍的如何解决mybatis--java.lang.illegalargumentexception: result maps collection already contains value for x,希望对大家有所帮助
推荐阅读
-
如何解决Mybatis--java.lang.IllegalArgumentException: Result Maps collection already contains value for X
-
如何解决Mybatis--java.lang.IllegalArgumentException: Result Maps collection already contains value for X
-
使用mybatis报错【Result Maps collection already contains value for ...BaseResultMap】的解决方法
-
java.lang.IllegalArgumentException: Result Maps collection already contains value for
-
Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for ...
-
java.lang.IllegalArgumentException: Result Maps collection already contains value for
-
Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for.....
-
解决:Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for xxx
-
Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for……
-
java.lang.IllegalArgumentException: Result Maps collection already contains value for ...