mybatis generator demo

带界面版的mybatis geneator,https://github.com/astarring/mybatis-generator-gui

参考  http://www.cnblogs.com/yjmyzz/p/4210554.html

实现如下:

1.pom.xml 中添加mybatis genarator 和 mysql 驱动的plugin

 1 <plugin>
 2     <!--mybatis generator-->
 3     <groupId>org.mybatis.generator</groupId>
 4     <artifactId>mybatis-generator-maven-plugin</artifactId>
 5     <version>1.3.2</version>
 6     <configuration>
 7         <!--generatorConfig.xml的位置,根据实际情况自行调整-->
 8         <configurationFile>src/main/resources/mybatis-generator/generatorConfig.xml</configurationFile>
 9         <verbose>true</verbose>
10         <overwrite>true</overwrite>
11     </configuration>
12     <executions>
13         <execution>
14             <id>Generate MyBatis Artifacts</id>
15             <goals>
16                 <goal>generate</goal>
17             </goals>
18         </execution>
19     </executions>
20     <dependencies>
21         <dependency>
22             <groupId>org.mybatis.generator</groupId>
23             <artifactId>mybatis-generator-core</artifactId>
24             <version>1.3.2</version>
25         </dependency>
26         <!--mysql 驱动-->
27         <dependency>
28             <groupId>mysql</groupId>
29             <artifactId>mysql-connector-java</artifactId>
30             <version>5.1.37</version>
31             <scope>runtime</scope>
32         </dependency>
33     </dependencies>
34 </plugin>

2.generatorConfig.xml配置文件

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE generatorConfiguration
 3         PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
 4         "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
 5 <generatorConfiguration>
 6     <context id="MybatisGenerator" targetRuntime="MyBatis3">
 7         <plugin type="org.mybatis.generator.plugins.SerializablePlugin" />
 8         <!-- comment config   此处自动生成的文件没有注解-->
 9         <commentGenerator>
10             <property name="suppressDate" value="false"/>
11             <property name="suppressAllComments" value="true"/>
12         </commentGenerator>
13         <!--数据库连接-->
14         <jdbcConnection driverClass="com.mysql.jdbc.Driver"
15                         connectionURL="jdbc:mysql://192.168.181.174:3306/voice_test?
16                         autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=UTF-8
17                         &amp;allowMultiQueries=true&amp;useAffectedRows=true"
18                         userId="****"
19                         password="****"/>
20         <!--domain 生成的项目位置-->
21         <javaModelGenerator targetPackage="mybatis.generator.entity"
22                             targetProject="C:/source/springtest/src/main/java">
23             <property name="enableSubPackages" value="true"/>
24             <property name="trimStrings" value="true"/>
25         </javaModelGenerator>
26         <!--mapper.xml 生成的项目位置-->
27         <sqlMapGenerator targetPackage="mybatis.generator.entity.xml"
28                          targetProject="C:/source/springtest/src/main/java">
29             <property name="enableSubPackages" value="true"/>
30         </sqlMapGenerator>
31         <!--mapper.class 生成的项目位置-->
32         <javaClientGenerator targetPackage="mybatis.generator.mapper"
33                              targetProject="C:/source/springtest/src/main/java" type="XMLMAPPER">
34             <property name="enableSubPackages" value="true"/>
35         </javaClientGenerator>
36         <!--具体要生成的表-->
37         <table tableName="question" domainObjectName="Question">
38             <generatedKey column="id" sqlStatement="MySql" identity="true"/>
39         </table>
40         <table tableName="likes" domainObjectName="Like">
41             <generatedKey column="id" sqlStatement="MySql" identity="true"/>
42         </table>
43         <table tableName="sticky" domainObjectName="Sticky">
44             <generatedKey column="id" sqlStatement="MySql" identity="true"/>
45         </table>
46     </context>
47 </generatorConfiguration>

3.使用方式

目录结构图如下

 

 

posted @ 2017-08-01 17:04  果壳里的星星  阅读(641)  评论(0编辑  收藏  举报