在项目开发的时候,习惯于先定义数据库表,给表字段写好注释,方便自己也方便他人。因为使用Mybatis的话,dao、domain、xml等文件基本上没有逻辑,都是基本的数据库操作语句,也就不想自己手写了(太费劲,也容易出错,想想一个包括20多个字段的表。。。),因此想到使用自动化插件来帮助放飞自我 。
使用Mybatis-generator插件的方法网上都有,随便一搜就可以看到。它包括如下几个模块:
1、在欲使用Mybatis-generator插件的功能模块的pom.xml中加入以下配置:
<build>
<plugins>
<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>
<!-- 数据库 Mysql -->
<dependency