异常:java.lang.IllegalArgumentException: Result Maps collection already contains value

pmsa
978
2021-05-13

原因:

使用 mybatis generator逆向工程多次生成 mapper 时,未将之前生成的 mapper.xml 删除,导致其在原有的xml里面追加内容。最终导致 BaseResultMap 重复

解决方法:

方法一,删除已生成的 mapper.xml 文件, 重新生成即可。

方法二 (能彻底解决问题)

  1. 升级MyBatis Generator的版本
<!-- MyBatis 生成器 -->
<dependency>
    <groupId>org.mybatis.generator</groupId>
    <artifactId>mybatis-generator-core</artifactId>
    <version>1.3.7</version>
</dependency>

  1. 在generatorConfig.xml文件中添加覆盖mapper.xml的插件
<!--生成mapper.xml时覆盖原文件-->
<plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin" />

  1. 重新运行代码生成器
动物装饰