The maven plugin mybatis-generator is automatically generated

1. Create a new maven project and add the following in pom.xml:

 

<plugins>
    <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>
                <configuration>
                    <verbose>false</verbose>
                    <overwrite>false</overwrite>
                </configuration>
            </plugin>
    </plugins>

 

2. Add the generatorConfig.xml file to the project src/main/resources

generatorConfig.xml content:

<span style="font-size:14px;"><?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:\Eclipse\Repository\mysql\mysql-connector-java\5.1.29\mysql-connector-java-5.1.29.jar" />
        <context id="context1" targetRuntime="MyBatis3">
        <commentGenerator>
        <!-- 是否去除自动生成的注释 true:是 : false:否 -->
        <property name="suppressAllComments" value="true" />      </commentGenerator>
        <!--Database connection information: driver class, connection address, user name, password-->

        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
            connectionURL="jdbc:mysql://localhost:3306/data?useUnicode=true&characterEncoding=UTF-8"
            userId="root" password="123456" />
        <javaModelGenerator targetPackage="org.share.domain.tree.entity"
            targetProject="E:\workspace\share\share-domain\src\main\java" />
        <sqlMapGenerator targetPackage="org.share.domain.tree.mapper"
            targetProject="E:\workspace\share\share-domain\src\main\java" />
        <javaClientGenerator targetPackage="org.share.domain.tree.mapper"
            targetProject="E:\workspace\share\share-domain\src\main\java" type="XMLMAPPER" />
          <!-- shema database tableName indicates -->
         <table schema="data" tableName="tree" />
       
    </context>
</generatorConfiguration></span>

 

Other attributes of table: 
enableCountByExample="false" 
enableUpdateByExample="false" 
enableDeleteByExample="false" 
enableSelectByExample="false" 
selectByExampleQueryId="false" 
schema is the database name, tableName is the corresponding database table, domainObjectName is the entity class to be generated, 
If you want the mapper configuration file to be added to the where condition query of sql, you can set enableCountByExample to true, 
which will generate an Example class corresponding to domainObjectName. When enableCountByExample is set to false, 
the corresponding Example class will not be generated.

 

3. Select the pom.xml configuration file in the project, right-click run -- "maven bulid --" Goals in the dialog box and enter mybatis-generator:generate as shown in the figure

 

 

 

4. Refresh the project src directory to see the mapped xml and interface files

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326214720&siteId=291194637