- pom.xml添加插件
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<!-- 配置文件位置 -->
<configurationFile>src/test/resources/generatorConfig.xml</configurationFile>
<!-- 文件存在的话覆盖(true)还是拼接(false) -->
<overwrite>true</overwrite>
<!-- 是否打印日志信息 -->
<verbose>true</verbose>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.21</version>
</dependency>
</dependencies>
</plugin>
- 在插件指定位置添加配置文件generatorConfig.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="default" targetRuntime="MyBatis3Simple">
<commentGenerator>
<!-- 去除所有注释 -->
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!-- 数据库连接 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/test?serverTimezone=GMT%2B8"
userId="xxxxx" password="xxxxx">
<property name="nullCatalogMeansCurrent" value="true" />
</jdbcConnection>
<!-- Model的位置 -->
<javaModelGenerator targetPackage="com.xxx.jk.pojo.po"
targetProject="src/test/java"/>
<!-- XML的位置 -->
<sqlMapGenerator targetPackage="com.xxx.jk.mapper"
targetProject="src/test/resources"/>
<!-- Mapper的位置 -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.xxx.jk.mapper"
targetProject="src/test/java"/>
<!-- %代表所有表 -->
<table tableName="%"/>
<!-- <table tableName="dict_type"/>-->
</context>
</generatorConfiguration>
- 右侧maven工具栏中找到mybatis-generator插件,执行generate