Use the maven plugin mybatis-generator to automatically generate the mybatis configuration file in the idea

1. Add in the pom.xml file:
<!--myibatis3 Automatically generate configuration xml file plugin-->
<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. In Add the generatorConfig.xml file to the project src/main/resources, the content is as follows:
<!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:\myIdea\mylib\ojdbc6.jar"/>
    <context id="context1" targetRuntime="MyBatis3">
        <commentGenerator>
            <!-- Whether to remove automatically generated comments true: yes : false: no -->
            <property name="suppressAllComments" value="true"/>
            <!--Database connection information: driver class, connection address, username, password -->
        </commentGenerator>
        <jdbcConnection driverClass ="oracle.jdbc.OracleDriver"
                        connectionURL="jdbc:oracle:thin:@192.168.16.24:1522:BOCE"
                        userId="shiro" password="shiro"/>
<!-- Entity pojo path-->
        <javaModelGenerator targetPackage="org.boce.entity"
                            targetProject="E:\projectSrc"/>
<!--Generate interface path-->
        <sqlMapGenerator targetPackage="org.boce.mapper"
                         targetProject="E:\projectSrc"/>
<!-- Generate xml location-- >
        <javaClientGenerator targetPackage="org.boce.mapper"
                             targetProject="E:\projectSrc"
                             type="XMLMAPPER"/>
        <!-- shema database tableName indicates -->
        <table schema="shiro" tableName="demopo" />


    </context>
</generatorConfiguration>

table other attributes: 
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, etc. to true, then an Example class corresponding to domainObjectName will be generated. When enableCountByExample is set to false, the corresponding Example class will not be generated. 

3. Configure the idea:

click "edit Configurations" in the upper right corner and select "+", Find maven in the list and click, enter the following figure, and configure it:
Command line: mybatis-generator:generate -e






After the addition is complete, you can see it in the upper corner. Click Run to generate the configuration file.




Guess you like

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