之前开发了一个亚健康测评系统,使用的是SSM框架,里面第一次使用到了mybatis-generator逆向代码生成工具,很方便,省去了基本的增删改查的mapper文件及sql的编写,还能避免错误,这里推荐一下!
当然,使用该工具的前提是你得有这个工具。他的下载地址为:https://github.com/mybatis/generator/releases
如果使用Maven就不需要下载了,见pom.xml文件配置即可
在你建好数据库的前提下,该工具才能发挥作用,而且数据表必须包含主键,生成的select方法都是根据主键查找的。
以下是配置文件
pom.xml中加入插件
1 <plugin> 2 <groupId>org.mybatis.generator</groupId> 3 <artifactId>mybatis-generator-maven-plugin</artifactId> 4 <version>1.3.2</version> 5 <configuration> 6 <configurationFile>src/main/resources/mybatis-generator/generatorConfig.xml</configurationFile> 7 <verbose>true</verbose> 8 <overwrite>true</overwrite> 9 </configuration> 10 <executions> 11 <execution> 12 <id>Generate MyBatis Artifacts</id> 13 <goals> 14 <goal>generate</goal> 15 </goals> 16 </execution> 17 </executions> 18 <dependencies> 19 <dependency> 20 <groupId>org.mybatis.generator</groupId> 21 <artifactId>mybatis-generator-core</artifactId> 22 <version>1.3.2</version> 23 </dependency> 24 </dependencies> 25 </plugin>