1. pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.study</groupId>
<artifactId>MybatisGenerator</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>MybatisGenerator Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.2.7</version>
</dependency>
</dependencies>
<build>
<finalName>maven</finalName>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.1</version>
<configuration>
<configurationFile>src/main/resources/mybatis-generator.xml</configurationFile>
<overwrite>true</overwrite>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.26</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
2. mybatis-generator.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<!-- <classPathEntry location="E:\repo\mysql\mysql-connector-java\5.1.26\mysql-connector-java-5.1.26.jar" /> -->
<context id="generatorTables" targetRuntime="MyBatis3">
<plugin type="org.mybatis.generator.plugins.MapperConfigPlugin">
<property name="fileName" value="mybatis-config.xml" />
<property name="targetPackage" value="/" />
<property name="targetProject" value="src/main/resources" />
</plugin>
<!-- 此处是将 Example 改名为 Criteria 想改成什么都行 -->
<plugin type="org.mybatis.generator.plugins.RenameExampleClassPlugin">
<property name="searchString" value="Example" />
<property name="replaceString" value="Criteria" />
</plugin>
<plugin type="org.mybatis.generator.plugins.SerializablePlugin" />
<!-- commentGenerator 去除自动生成的注释 -->
<commentGenerator>
<property name="suppressAllComments" value="true" />
<property name="suppressDate" value="true" />
</commentGenerator>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://127.0.0.1:3306/test" userId="root"
password="test">
</jdbcConnection>
<!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer true, 把 JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- javaModelGenerator是模型的生成信息,这里将指定这些Java model类的生成路径; -->
<javaModelGenerator targetPackage="org.study.model"
targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- sqlMapGenerator是mybatis 的sqlMapper XML文件的生成信息,包括生成路径等; 先生成xml,在生成java -->
<sqlMapGenerator targetPackage="org.study.dao"
targetProject="src/main/resources">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- javaClientGenerator是应用接口的生成信息; -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="org.study.dao" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- table是用户指定的被生成相关信息的表,它必须在指定的jdbc连接中已经被建立。?是否可以多个 -->
<table tableName="cust_info" domainObjectName="CustInfo"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false"></table>
<!-- <table tableName="app_bind_status" domainObjectName="AppBindStatus"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false"></table> -->
</context>
</generatorConfiguration>
<!-- mybatis-generator:generate 执行命令-->
3. 工程右键 Debug As -> maven build... -> mybatis-generator:generate