Result Maps collection already contains value for xxxMapper.BaseResultMap错误解决办法
一、问题描述
今天在做项目时,遇到一个错误:“Result Maps collection already contains value for com.xxx.dao.tb_userMapper.BaseResultMap”

最简单的方法就是将逆向工程在eclipse中移除掉,然后重新import这个逆向工程,然后重新生成mapper文件。

因为如果之前生成过一张相同的表,逆向工程会再生成,导致内容重复,报该表的错误。
二、原因分析
    Mybatis-Generator在生成Mapper.xml文件时,会在原来基础上再生成,导致内容重复。
三、解决办法
(1)改造Mybatis-generator插件
    参考mybatis-generator重新生成代码时的SQL映射文件覆盖
(2)将手写xml文件与自动生成xml文件分离
    手写文件放在src/main/resources/mybatis目录中
    生成文件放在src/main/resources/mybatis-generator目录中,这样便于在生成之前手动删除。
    generatorConfig.xml配置:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >
<generatorConfiguration>
    <classPathEntry
        location="D:\Java\maven\repository\mysql\mysql-connector-java\5.1.31\mysql-connector-java-5.1.31.jar" />
    <context id="aisSnsTables" targetRuntime="MyBatis3">
        <plugin type="org.mybatis.generator.plugins.SerializablePlugin" />
        <plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin" />
        <plugin type="org.mybatis.generator.plugins.ToStringPlugin" />
        <!-- 抑制生成代码的注释 -->
        <commentGenerator>
            <property name="suppressAllComments" value="true" />
        </commentGenerator>
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
            connectionURL="jdbc:mysql://localhost:3306/liying" userId="root"
            password="root@" />
        <javaModelGenerator targetPackage="com.uni2uni.model"
            targetProject="src/main/java" />
        <sqlMapGenerator targetPackage="/"
            targetProject="src/main/resources/mybatis-generator" />
        <javaClientGenerator targetPackage="com.uni2uni.dao"
            targetProject="src/main/java" type="XMLMAPPER">
            <property name="enableSubPackages" value="true" />
        </javaClientGenerator>
        <table schema="liying" tableName="tb_user" domainObjectName="tb_user" />
        <table schema="liying" tableName="tb_admin" domainObjectName="tb_admin" />
        <table schema="liying" tableName="tb_role" domainObjectName="tb_role" />
        <table schema="liying" tableName="tb_resource" domainObjectName="tb_resource" />
        <table schema="liying" tableName="tb_user_role" domainObjectName="tb_user_role" />
        <table schema="liying" tableName="tb_role_resource" domainObjectName="tb_role_resource" />
        <table schema="liying" tableName="tb_category" domainObjectName="tb_category"/>
        <table schema="liying" tableName="tb_shop" domainObjectName="tb_shop"/>
    </context>
</generatorConfiguration>

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 alias="user" type="com.uni2uni.model.tb_user" />
        <typeAlias alias="admin" type="com.uni2uni.model.tb_admin" />
        <typeAlias alias="role" type="com.uni2uni.model.tb_role" />
        <typeAlias alias="resource" type="com.uni2uni.model.tb_resource" />
        <typeAlias alias="category" type="com.uni2uni.model.tb_category" />
        <typeAlias alias="shop" type="com.uni2uni.model.tb_shop" />
    </typeAliases>
    <plugins>
        <plugin
            interceptor="com.github.miemiedev.mybatis.paginator.OffsetLimitInterceptor">
            <property name="dialectClass"
                value="com.github.miemiedev.mybatis.paginator.dialect.MySQLDialect" />
        </plugin>
    </plugins>
    <mappers>
        <mapper resource="mybatis/tb_user.xml" />
        <mapper resource="mybatis-generator/tb_userMapper.xml" />
        <mapper resource="mybatis/tb_admin.xml" />
        <mapper resource="mybatis-generator/tb_adminMapper.xml" />
        <mapper resource="mybatis/tb_role.xml" />
        <mapper resource="mybatis-generator/tb_roleMapper.xml" />
        <mapper resource="mybatis/tb_resource.xml" />
        <mapper resource="mybatis-generator/tb_resourceMapper.xml" />
        <mapper resource="mybatis/tb_user_role.xml" />
        <mapper resource="mybatis-generator/tb_user_roleMapper.xml" />
        <mapper resource="mybatis/tb_role_resource.xml" />
        <mapper resource="mybatis-generator/tb_role_resourceMapper.xml" />
        <mapper resource="mybatis/tb_category.xml" />
        <mapper resource="mybatis-generator/tb_categoryMapper.xml" />
        <mapper resource="mybatis/tb_shop.xml" />
        <mapper resource="mybatis-generator/tb_shopMapper.xml" />
    </mappers>

</configuration>

mybatis逆向工程生成mapper报错的更多相关文章

  1. MyBatis逆向工程中domainObjectRenamingRule报错或无效

    使用domainObjectRenamingRule报错 在使用MyBatis逆向工程时报错如下: org.mybatis.generator.exception.XMLParserException ...

  2. Mybatis逆向工程生成po、mapper接口、mapper.xml

    Mybatis逆向工程生成po.mapper接口.mapper.xml 一.新建一个maven工程 请查看我的另一篇博客:<使用idea创建一个maven工程> 二.引入所需依赖 需要my ...

  3. mybatis 映射生成mapper和pojo ---逆向工程的使用过程

    使用逆向工程生成mapper和pojo 2. 新建一个项目,随便叫什么 3.导入mybatis-generator-core .mybatis.mybatis-spring.log4j等jar 4.在 ...

  4. MyBatis逆向工程生成配置 generator (生成pojo、mapper.xml、mapper.java)

    MyBatis逆向工程生成 mybatis需要程序员自己编写sql语句,mybatis官方提供逆向工程,可以针对单表自动生成mybatis执行所需要的代码(mapper.java.mapper.xml ...

  5. 使用mybatis-generator插件结合tk.mybatis自动生成mapper二三事

    本篇文章将介绍使用spring boot框架,引入mybatis-generator插件,结合tk.mybatis自动生成Mapper和Entity的一整套流程,其中包括最重要的踩坑与填坑.     ...

  6. MyBatis逆向工程生成的Example类的方法总结

    很早之前就在项目开发中多次使用MyBatis逆向工程生成的Example类,但一直没有对其下的方法做一个简单的总结,现总结如下:一.mapper接口中的方法解析mapper接口中的部分常用方法及功能如 ...

  7. 使用mybatis-generator插件结合tk.mybatis自动生成mapper

    本篇文章将介绍使用spring boot框架,引入mybatis-generator插件,结合tk.mybatis自动生成Mapper和Entity的一整套流程,其中包括最重要的踩坑与填坑.     ...

  8. idea的service注入mapper报错

    一.问题 idea的java项目中,service类中注入mapper报错 二.解决 方法1 在mapper类上加上  @Repository 注解即可,当然不加也行,程序也不回报错,是idea的误报 ...

  9. 用itext生成PDF报错:Font 'STSong-Light1' with 'UniGB-UCS2-H' is not recognized.

    用itext生成PDF报错,加上try catch捕获到异常是 BaseFont bFont = BaseFont.createFont("STSong-Light1", &quo ...

随机推荐

  1. Redis4.0支持的新功能说明

    本文以华为云DCS for Redis版本为例,介绍Redis4.0的新功能.文章转载自华为云帮助中心. 与Redis3.x版本相比,DCS的Redis4.x以上版本,除了开源Redis增加的特性之外 ...

  2. 【MySQL解惑笔记】Navicat 无法远程连接MySQL数据库

    安装好Navicat之后远程连接MySQL数据库出现以下报错截图: 出现以上截图怀疑是mysql用户权限不够: GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.1 ...

  3. VBA基础之Excel VBA 表格的操作(一)

    一.Excel VBA 表格的操作1. Excel表格的指定以及表格属性的设置 Sub main() '把表格B2的值改为"VBA Range和Cells函数" Range(&qu ...

  4. 数组的引用——用作形参&返回类型时

    一.数组的引用 切入:可以将一个变量定义成数组的引用(这个变量和数组的类型要相同) 形式: int odd[5] = {1, 3, 5, 7, 9}; int (&arr)[5] = odd; ...

  5. “Hello world!”团队第一周贡献分分配结果

    小组名称:Hello World! 项目名称:空天猎 组长:陈建宇 成员:刘成志.阚博文.刘淑霞.黄泽宇.方铭.贾男男 第一周贡献分分配结果   基础分 会议分 提功能分 个人表现分 各项总分 最终分 ...

  6. Java实验二实验报告:java面向对象程序设计

    java实验二实验报告 实验内容 1. 初步掌握单元测试和TDD 2. 理解并掌握面向对象三要素:封装.继承.多态 3. 初步掌握UML建模 4. 熟悉S.O.L.I.D原则 5. 了解设计模式 实验 ...

  7. VUE01指令

    一.下载Vue2.0的两个版本: 官方网站:http://vuejs.org/ 开发版本:包含完整的警告和调试模式 生产版本:删除了警告,进行了压缩 二.项目结构搭建 这个部分要视频中有详细讲解. 三 ...

  8. Jenkins系列-Jenkins升级、迁移和备份

    升级Jenkins Jenkins的开发迭代非常快,每周发布一个开发版本,长期支持版每半年更新一次(ps:大版本更新).如此频繁的更新,怎么升级呢? war:下载新版的war文件,替换旧版本war文件 ...

  9. BZOJ 1211 树的计数(purfer序列)

    首先考虑无解的情况, 根据purfer序列,当dee[i]=0并且n!=1的时候,必然无解.否则为1. 且sum(dee[i]-1)!=n-2也必然无解. 剩下的使用排列组合即可推出公式.需要注意的是 ...

  10. BZOJ 1025 游戏(分组背包)

    题目所谓的序列长度实际上就是各循环节的lcm+1. 所以题目等价于求出 一串数之和等于n,这串数的lcm种数. 由唯一分解定理可以联想到只要把每个素数的幂次放在一个分组里,然后对整体做一遍分组背包就行 ...