记一次使用mybatis-generator产生的错误
描述一下:最近在学习mybatis三剑客。第一次使用mybatis-generator插件,逆向工程生成实体类、mapper接口层以及mapper.xml时候,使用命令mvn tomcat7:run时,mapper层再次逆向工程生成的代码追加了一次。导致如下错误:
org.apache.ibatis.exceptions.PersistenceException:
### Error building SqlSession.
### The error may exist in mapper/TbGoodMapper.xml
### The error occurred while processing mapper_resultMap[BaseResultMap]
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing M
apper XML. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.qf.mapper.TbGoodMapper.BaseResultMap
mapper.xml文件本来只有
在执行mvn tomcat7:run命令之后
mapper.xml文件行数变成418行,并且id全部标红:
发现是pom.xml的插件信息写错:
错误插件配置如下:
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<!-- 文件路径-->
<configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
<executions>
<execution>
<id>Generate MyBatis Artifacts</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
</dependencies>
</plugin>
修改为如下配置信息就结果正常了:
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.44</version>
</dependency>
</dependencies>
<configuration>
<!--配置文件的路径-->
<configurationFile>${basedir}/src/main/resources/generatorConfig.xml</configurationFile>
<overwrite>true</overwrite>
</configuration>
</plugin>
因该是因为extensions:true or false, 决定是否要load这个plugin的extensions,默认为true。所以在运行的时候又一次执行了这个插件?