Recommend a mybatis plugin-reverse generation of mapper and entity classes

Add maven dependency

pom.xml add plugin dependency


    <build>
        <plugins>
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</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.2</version>
                    </dependency>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>5.1.42</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

Create the configuration file corresponding to <configurationFile> in the maven dependency

<?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="E:\repo\mysql\mysql-connector-java\5.1.26\mysql-connector-java-5.1.26.jar" /> -->  
    <context id="generatorTables" targetRuntime="MyBatis3">
    <!-- sqlMapconfig 默认不生成 -->
<!--         <plugin type="org.mybatis.generator.plugins.MapperConfigPlugin">  
            <property name="fileName" value="sqlMapConfig.xml" />  
            <property name="targetPackage" value="/" />  
            <property name="targetProject" value="src/main/resources" />  
        </plugin>   -->
  
        <!-- 此处是将 Example 改名为 Criteria -->  
        <plugin type="org.mybatis.generator.plugins.RenameExampleClassPlugin">  
            <property name="searchString" value="Example" />  
            <property name="replaceString" value="Criteria" />  
        </plugin>  
  
        <plugin type="org.mybatis.generator.plugins.SerializablePlugin" />  
  
        <!-- commentGenerator 去除自动生成的注释 -->  
        <!--<commentGenerator type="com.youli.prod.util.CustomCommentGenerator">-->
            <!--<property name="suppressAllComments" value="false" />-->
            <!--<property name="suppressDate" value="true" />  -->
        <!--</commentGenerator>-->
        <commentGenerator>
            <property name="suppressAllComments" value="true" />
            <property name="suppressDate" value="true" />
        </commentGenerator>
  
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"  
            connectionURL="jdbc:mysql://mysql_db_host:3306/ltn_product" userId="yluser"
            password="Yl#sit&amp;2018">
        </jdbcConnection> 
  
        <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer true, 把 JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal -->  
        <javaTypeResolver>  
            <property name="forceBigDecimals" value="false" />  
        </javaTypeResolver>  
  
        <!-- javaModelGenerator是模型的生成信息,这里将指定这些Java model类的生成路径; -->  
        <javaModelGenerator targetPackage="test"
            targetProject="src/main/java">  
            <property name="enableSubPackages" value="true" />  
            <property name="trimStrings" value="true" />  
        </javaModelGenerator>  
  
        <!-- sqlMapGenerator是mybatis 的sqlMapper XML文件的生成信息,包括生成路径等; 先生成xml,在生成java -->  
        <sqlMapGenerator targetPackage="test"
            targetProject="src/main/java">  
            <property name="enableSubPackages" value="true" />  
        </sqlMapGenerator>  
  
        <!-- javaClientGenerator是应用接口的生成信息; -->  
        <javaClientGenerator type="XMLMAPPER"  
            targetPackage="test" targetProject="src/main/java">
            <property name="enableSubPackages" value="true" />  
        </javaClientGenerator>  
  
        <!-- table是用户指定的被生成相关信息的表,它必须在指定的jdbc连接中已经被建立。 -->  
        <table tableName="yl_auction_goods" domainObjectName="AuctionGoods"
             enableCountByExample="false" enableUpdateByExample="false"
             enableDeleteByExample="false" enableSelectByExample="false"
             selectByExampleQueryId="false">
        </table>
  
    </context>  
</generatorConfiguration>   

Double-click to execute the plugin
Double-click to execute the plugin

Guess you like

Origin blog.csdn.net/ouyangli2011/article/details/90081459