Import the jar package of the automatically generated file and the jar package of the link mysql
pom.xml add [note that it is added in the build tag]
<build>
<plugins>
<plugin>
<!-- configure generator-->
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2 </version>
<configuration>
<!--Allow generated files to be moved-->
<verbose>true</verbose>
<!--Allow generated files to be overwritten-->
<overwrite>true</overwrite>
</configuration >
</plugin>
</plugins>
</build>
Configure generatorConfig.xml [modify accordingly]
<?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="D:\workspace\hello\target\mysql-connector-java-5.1.30.jar" />
<context id="MysqlTables" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!--Database connection information: driver class, connection address, username, password -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://127.0.0.1:3306/database name" userId="username"
password="password">
</jdbcConnection>
<!-- default false, resolve JDBC DECIMAL and NUMERIC types to Integer true,
resolve JDBC DECIMAL and NUMERIC types to java.math.BigDecimal -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- targetProject: The location of the automatically generated code-->
<!-- Entity class generation file path -->
<javaModelGenerator targetPackage="com.example.demo.domain"
targetProject="src\main\java">
<!-- enableSubPackages: Whether to use schema as the suffix of the package -->
<property name="enableSubPackages" value="true " />
<!-- Whitespace before and after values returned from the database are trimmed -->
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- mapper.xml generated file path -->
<sqlMapGenerator targetPackage="mapper"
targetProject="src\main\resources">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- dao generated file path -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.example.demo.dao" targetProject="src\main\java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- tableName: database table used to generate code automatically; domainObjectName: javaBean class name corresponding to database table -->
<table schema="dispatch" tableName="database corresponding table" domainObjectName=" entity class corresponding name"
enableCountByExample="false " enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
<!-- Deny CamelCase -->
<property name="useActualColumnNames" value="true" />
</table>
</context>
</generatorConfiguration>
Then run: Click on the project run as -->run configurations...--->Goals and fill in mybatis-generator:generate