一.pom 文件, 加入如下代码
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<configurationFile>${basedir}/src/main/resources/mybatis_generate.xml</configurationFile>
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
<dependencies>
<!-- 此处添加一个 mysql-connector-java 依赖可以防止找不到 jdbc Driver-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.28</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
二.resources 文件夹下创建 mybatis_generate.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>
<context id="context" targetRuntime="MyBatis3">
<!--oracla-->
<!--connectionURL="jdbc:oracle:thin:@172.16.182.18:1521:orcl"-->
<!--driverClass="oracle.jdbc.driver.OracleDriver"-->
<jdbcConnection
driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/test?serverTimezone=CTT"
userId="root" password="root" />
<javaModelGenerator
targetPackage="com.rainbow.test.model"
targetProject="src/main/java">
<property name="enableSubPackages" value="false" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<sqlMapGenerator targetPackage="com.rainbow.test.mapper"
targetProject="src/main/resources">
<property name="enableSubPackages" value="false" />
<property name="isMergeable" value="false" />
</sqlMapGenerator>
<javaClientGenerator
targetPackage="com.rainbow.test.mapper"
targetProject="src/main/java" type="XMLMAPPER">
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<table tableName="person"></table>
</context>
</generatorConfiguration>
三. 运行 maven 插件命令:mybatis-generator:generate
成功 …