Java自学者论坛

 找回密码
 立即注册

手机号码,快捷登录

恭喜Java自学者论坛(https://www.javazxz.com)已经为数万Java学习者服务超过8年了!积累会员资料超过10000G+
成为本站VIP会员,下载本站10000G+会员资源,会员资料板块,购买链接:点击进入购买VIP会员

JAVA高级面试进阶训练营视频教程

Java架构师系统进阶VIP课程

分布式高可用全栈开发微服务教程Go语言视频零基础入门到精通Java架构师3期(课件+源码)
Java开发全终端实战租房项目视频教程SpringBoot2.X入门到高级使用教程大数据培训第六期全套视频教程深度学习(CNN RNN GAN)算法原理Java亿级流量电商系统视频教程
互联网架构师视频教程年薪50万Spark2.0从入门到精通年薪50万!人工智能学习路线教程年薪50万大数据入门到精通学习路线年薪50万机器学习入门到精通教程
仿小米商城类app和小程序视频教程深度学习数据分析基础到实战最新黑马javaEE2.1就业课程从 0到JVM实战高手教程MySQL入门到精通教程
查看: 10764|回复: 0

mybatis generator自动生成代码报The error occurred while processing mapper_resultMap[BaseResultMap]错误的解决方法

[复制链接]
  • TA的每日心情
    奋斗
    2024-11-24 15:47
  • 签到天数: 804 天

    [LV.10]以坛为家III

    2053

    主题

    2111

    帖子

    72万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    726782
    发表于 2021-4-11 17:26:53 | 显示全部楼层 |阅读模式

    今天在用mybatis自动生成代码之后遇到了一个错误:

    ?
     
    org.apache.ibatis.exceptions.PersistenceException :
    ### Error building SqlSession.
    ### The error may exist in com/erp/webservice/mapper/UsersMapper.xml
    ### The error occurred while processing mapper_resultMap[BaseResultMap]
    ### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.RuntimeException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException : Result Maps collection already contains value for com.erp.webservice.inter.UsersMapper.BaseResultMap
          at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java: 23 )
          at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java: 51 )
          at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java: 35 )
          at com.erp.webservice.test.Test.<clinit>( Test.java: 22 )
    Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.RuntimeException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException : Result Maps collection already contains value for com.erp.webservice.inter.UsersMapper.BaseResultMap
          at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java: 107 )
          at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java: 89 )
          at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java: 49 )
          ... 2 more
    Caused by: java.lang.RuntimeException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException : Result Maps collection already contains value for com.erp.webservice.inter.UsersMapper.BaseResultMap
          at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java: 113 )
          at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java: 88 )
          at org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java: 325 )
          at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java: 105 )
          ... 4 more
    Caused by: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.erp.webservice.inter.UsersMapper.BaseResultMap
          at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java: 710 )
          at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java: 682 )
          at org.apache.ibatis.session.Configuration.addResultMap(Configuration.java: 473 )
          at org.apache.ibatis.builder.MapperBuilderAssistant.addResultMap(MapperBuilderAssistant.java: 204 )
          at org.apache.ibatis.builder.ResultMapResolver.resolve(ResultMapResolver.java: 44 )
          at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java: 277 )
          at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java: 244 )
          at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElements(XMLMapperBuilder.java: 236 )
          at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java: 109 )
          ... 7 more
    Exception in thread "main" java.lang.NullPointerException
          at com.erp.webservice.test.Test.main( Test.java: 29 )

    后来发现是我运行了多次自动生成代码的程序,导致了com/erp/webservice/mapper/UsersMapper.xml的内容多出来很多,原来自动生成代码的时候生成的XML代码不是覆盖原来的,而是附加的XML的尾部的。

    第一次运行自动生成代码程序:

    mapper1

     

     

     

     

     

     

    第二次运行自动生成代码程序:

    mapper2

     

     

     

     

     

     

    看看,XML文件明显大了很多,只要删掉原来的XML然后重新运行自动生成代码的程序即可。

    或者去工作空间吧生成的东西都删除一边重新生成

    哎...今天够累的,签到来了1...
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|手机版|小黑屋|Java自学者论坛 ( 声明:本站文章及资料整理自互联网,用于Java自学者交流学习使用,对资料版权不负任何法律责任,若有侵权请及时联系客服屏蔽删除 )

    GMT+8, 2024-12-23 05:48 , Processed in 0.128080 second(s), 29 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表