Result Maps collection already contains value for XXXMAPPER.BASERESULTMAP error resolution
I. Description of the problem
Today, I encountered an error while doing the project: "Result Maps collection already contains value for Com.xxx.dao.tb_userMapper.BaseResultMap"
Second, the reason analysis
Mybatis-generator generates mapper.xml files and then builds on the original, resulting in duplicate content.
Iii. Solutions
(1) Transformation of Mybatis-generator Plug-ins
Reference mybatis-generator SQL Map file overwrite when code is regenerated
(2) Separating the handwritten XML file from the auto-generated XML file
The handwriting files are placed in the Src/main/resources/mybatis directory
The makefile is placed in the Src/main/resources/mybatis-generator directory so that it is easy to delete manually before the build.
Generatorconfig.xml configuration:
<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE generatorconfiguration Public "-//mybatis.org//dtd mybatis generator Configuration" "1.0//en 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"/>
<!--to suppress comment on generated code-->
<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 configuration:
<?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>