当前位置: 首页 > news >正文

Result Maps collection already contains value for xxxMapper.BaseResultMap错误解决办法

Result Maps collection already contains value for xxxMapper.BaseResultMap错误解决办法
一、问题描述
今天在做项目时,遇到一个错误:“Result Maps collection already contains value for com.xxx.dao.tb_userMapper.BaseResultMap”
二、原因分析
    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>


相关文章:

  • Tomcat version 6.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 Web modules (web项目不能加载到服务器))
  • Javascript 闭包详解!
  • uedito在线管理图片无法预览的问题
  • Redis 简介和安装
  • org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
  • Java基础笔记1-计算机基础
  • windows下JDK安装和配置
  • nested exception is java.lang.NoClassDefFoundError: org/apache/commons/pool2/impl/GenericObjectPoolC
  • 警告:不能读取 AppletViewer 的属性文件
  • JDK目录结构
  • IIS8.0, IIS7.0提示“请求筛选模块被配置为拒绝包含双重转义序列的请求”处理办法
  • linux、windows中ping大数据包的命令格式
  • IIS7中的自定义 404页面错误- 500.19
  • 关于struts2中action请求会执行两次的问题
  • 解决Mac OS lion下(ubuntu等linux也一样)启动tomcat的Cannot find ./catalina.sh 的问题
  • “Material Design”设计规范在 ComponentOne For WinForm 的全新尝试!
  • 78. Subsets
  • CentOS学习笔记 - 12. Nginx搭建Centos7.5远程repo
  • es6
  • express如何解决request entity too large问题
  • Git 使用集
  • happypack两次报错的问题
  • maya建模与骨骼动画快速实现人工鱼
  • redis学习笔记(三):列表、集合、有序集合
  • Stream流与Lambda表达式(三) 静态工厂类Collectors
  • Vim Clutch | 面向脚踏板编程……
  • Webpack 4x 之路 ( 四 )
  • 阿里云容器服务区块链解决方案全新升级 支持Hyperledger Fabric v1.1
  • 对象管理器(defineProperty)学习笔记
  • 对象引论
  • 给Prometheus造假数据的方法
  • 推荐一个React的管理后台框架
  • 我的业余项目总结
  • 一文看透浏览器架构
  • 原创:新手布局福音!微信小程序使用flex的一些基础样式属性(一)
  • FaaS 的简单实践
  • Unity3D - 异步加载游戏场景与异步加载游戏资源进度条 ...
  • 国内唯一,阿里云入选全球区块链云服务报告,领先AWS、Google ...
  • 积累各种好的链接
  • 蚂蚁金服CTO程立:真正的技术革命才刚刚开始
  • ​Distil-Whisper:比Whisper快6倍,体积小50%的语音识别模型
  • #100天计划# 2013年9月29日
  • #include<初见C语言之指针(5)>
  • #LLM入门|Prompt#2.3_对查询任务进行分类|意图分析_Classification
  • #pragma multi_compile #pragma shader_feature
  • #pragma once
  • (4)STL算法之比较
  • (a /b)*c的值
  • (C++)八皇后问题
  • (C语言)输入一个序列,判断是否为奇偶交叉数
  • (第二周)效能测试
  • (附源码)springboot 校园学生兼职系统 毕业设计 742122
  • (教学思路 C#之类三)方法参数类型(ref、out、parmas)
  • (一)appium-desktop定位元素原理
  • (转)PlayerPrefs在Windows下存到哪里去了?