1.pom文件如下
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.30</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.6</version>
<configuration>
<configurationFile>GeneratorMapper.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.30</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
2.在该模块下直接新增GeneratorMapper.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>
<!--指定连接数据库的JDBC 驱动包所在位置,指定到你本机的完整路径-->
<!-- <classPathEntry location="E:\mysql-connector-java-5.1.40.jar"/>-->
<!--配置table表信息内容体,targetRuntime 指定采用MyBatis3的版本-->
<context id="tables" targetRuntime="MyBatis3">
<!--抑制生成注释,由于生成的注释都是英文的,可以不让它生成-->
<commentGenerator>
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!--配置数据库连接信息-->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/ylb"
userId="root"
password="123123">
<property name="nullCatalogMeansCurrent" value="true"/>
</jdbcConnection>
<!--生成model 类,targetPackage 指定 model 类的包名,targetProject 指定
生成的 model放在eclipse的哪个工程下面-->
<javaModelGenerator targetPackage="com.bjpowernode.api.entity"
targetProject="E:\IDEA_Project\ready\ready-04-mapper\src\main\java">
<property name="enableSubPackages" value="false"/>
<property name="trimStrings" value="false"/>
</javaModelGenerator>
<!--生成 MyBatis的Mapper.xml文件,targetPackage 指定 mapper.xml文件的包名,targetProject 指定生成的 mapper.xml放在 eclipse的哪个工程下面
-->
<sqlMapGenerator targetPackage="mappers"
targetProject="E:\IDEA_Project\ready\ready-04-mapper\src\main\resources">
<property name="enableSubPackages" value="false"/>
</sqlMapGenerator>
<!--生成 MyBatis的 Mapper接口类文件,targetPackage 指定 Mapper 接口类的包名,targetProject 指定生成的 Mapper 接口放在eclipse 的哪个工程下面-->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.bjpowernode.dataservice.mapper"
targetProject="E:\IDEA_Project\ready\ready-04-mapper\src\main\java">
<property name="enableSubPackages" value="false"/>
</javaClientGenerator>
<!--数据库表名及对应的Java模型类名-->
<table tableName="b_bid_info" domainObjectName="bidInfo"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false" />
<table tableName="b_income_record" domainObjectName="IncomeRecord"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false" />
<table tableName="b_product_info" domainObjectName="ProductInfo"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false" />
<table tableName="b_recharge_record" domainObjectName="RechargeRecord"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false" />
<table tableName="u_finance_account" domainObjectName="FinanceAccount"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false" />
<table tableName="u_user" domainObjectName="User"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false" />
</context>
</generatorConfiguration>
3.maven中双击mybatis-generator,generate
![](https://i-blog.csdnimg.cn/blog_migrate/3198f7bfe2ae53f73338c0ee1ebc24af.png)