Maven依赖
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.6</version>
<configuration>
<configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
<executions>
<execution>
<id>Generate MyBatis Artifacts</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.6</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>
<!--location 为本地 mysql jar 包地址,可去maven 仓库取-->
<classPathEntry
location="E:/develop_app/repository/mysql/mysql-connector-java/8.0.27/mysql-connector-java-8.0.27.jar"/>
<context id="my" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="false"/>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!--以下为数据库链接 driverClass connectionURL userId password 需修改-->
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://10.42.216.114:3306/smell?useUnicode=true"
userId="root"
password="123456"/>
<!-- 以下为实体类 地址 targetPackage targetProject -->
<javaModelGenerator targetPackage="com.tp.strive.smell.model"
targetProject=".\src\main\java">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!--以下为映射xml文件 路径地址 targetPackage targetProject -->
<sqlMapGenerator targetPackage="mapper"
targetProject=".\src\main\resources">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<!-- 以下为dao 接口路径地址 targetPackage targetProject -->
<javaClientGenerator targetPackage="com.tp.strive.smell.mapper"
targetProject=".\src\main\java" type="XMLMAPPER">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!--以下为数据库表 和实体类的对应关系 tableName 表名 domainObjectName 实体类类名 , mapperName =mapper接口命名, sqlProviderName=xml文件命名 mapper接口命名和xml文件如果不配置会自动命名为UserMapper-->
<table tableName="t_user" domainObjectName="User"
mapperName="UserDao" sqlProviderName="UserDao"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
<!--<columnRenamingRule searchString="^D_"
replaceString=""/>-->
</table>
</context>
</generatorConfiguration>
使用插件生成mapper文件
