Environment: mybatis2.x+mybatis generator plugin1.3
step:
1. In the pom file, add the following plugins:
<build> <plugins> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.2</version> <configuration> <verbose>true</verbose> <overwrite>true</overwrite> <configurationFile>${basedir} /src/test/resources/generatorConfig.xml</configurationFile> </configuration> </plugin> </plugins> </build>
Note: The location of generatorConfig.xml can be specified here. If not specified, it will be found in src/main/resources by default.
2. Copy generatorConfig.xml to src/test/resources. The content is as follows:
<?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="/usr/local/apache-maven/apache-maven-3.3.9/repository/mysql/mysql-connector-java/5.1.38/mysql-connector-java-5.1.38.jar" /> <context id="MysqlContext" targetRuntime="MyBatis3" defaultModelType="flat"> <property name="beginningDelimiter" value="`"/> <property name="endingDelimiter" value="`"/> <commentGenerator> <property name="suppressDate" value="true"/> </commentGenerator> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://192.168.210.132:3306/db_nono" userId="root" password="root"> </jdbcConnection> <javaModelGenerator targetPackage="com.nonobank.credit.domain.entity" targetProject="src/main/java"> <property name="trimStrings" value="true" /> </javaModelGenerator> <sqlMapGenerator targetPackage="resources.mapper" targetProject="src/main/java"/> <javaClientGenerator type="XMLMAPPER" targetPackage="com.nonobank.credit.domain.dao" targetProject="src/main/java"/> <table tableName="product_share" domainObjectName="ProductShare" enableUpdateByExample="false" enableDeleteByExample="false" enableCountByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> <!--<property name="useActualColumnNames" value="true"/>--> </table> </context> </generatorConfiguration>
It is mainly to configure the path of the xml of mapper, that is, the path of the interface corresponding to the mapper, and the path of the entity.
3. In the file directory, enter the maven command directly: mvn mybatis-generator:generate.
Reference Tutorial 2 : Official Tutorial
Reference Tutorial 3 : Official Tutorial of Chineseization
Refer to Tutorial 4 : a very detailed explanation of the generatorConfig.xml