Creating mybatis idea of reverse engineering: generator

1 configuration mybatis-generator plug-in project directory

 

<build>
        <plugins>
            <!-- mybatis逆向工程 -->
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>
                <configuration>
                    <!--配置文件的位置-->
                    <configurationFile>src/main/resources/generator/generatorConfig.xml</configurationFile>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
            </plugin>
        </plugins>
    </build>

 

2 reverse engineering profile generator.xml

jdbc.driverLocation=D:\\Java\\repository\\mysql\\mysql-connector-java\\5.1.32\\mysql-connector-java-5.1.32.jar
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.connectionURL=jdbc:mysql:///mytest
jdbc.userId=root
jdbc.password=root

3generatorConfig.xml

<? Xml Version = "1.0" encoding = "UTF-8" ?> 
<! DOCTYPE generatorConfiguration 
        the PUBLIC "- // mybatis.org//DTD the Configuration MyBatis Generator 1.0 // EN" 
        "http://mybatis.org/dtd /mybatis-generator-config_1_0.dtd " > 

< generatorConfiguration > 
    <-! import property configuration -> 
    < properties Resource =" generator.properties " > </ properties > 

    <-! specify a particular database jdbc driver jar package position -> 
    < classpathentry lOCATION = "$ {jdbc.driverLocation}" /> 

    <context id="default"targetRuntime = "MyBatis 3" > 

        <-! while optional, is intended to create a class, annotation control -> 
        < commentGenerator > 
            < Property name = "suppressDate" value = "to true" /> 
            < Property name = "suppressAllComments" value = "to true" /> 
        </ commentGenerator > 

        <-! JDBC database connection -> 
        < JdbcConnection
                 driverClass = "$ {} jdbc.driverClass" 
                the connectionURL = "$ {} jdbc.connectionURL"
                userId="${jdbc.userId}"
                password = "$ {} jdbc.password" > 
        </ JdbcConnection > 


        <-! nonessential, processor type, between the database type and the type of switching control java -> 
        < javaTypeResolver > 
            < Property name = "forceBigDecimals" value = "to false" /> 
        </ javaTypeResolver > 


        <-! the model model generator for generating class containing the primary key of the key, and a query record class Example class 
            package name specified targetPackage generated model generated where 
            targetProject specified in the project where the path 
        -> 
        < javaModelGenerator targetPackage = "com.ldf.shrioDemo.pojo"
                            targetProject= "the src / main / Java" > 

            <-! whether to allow sub-packet, i.e. targetPackage.schemaName.tableName -> 
            < Property name = "enableSubPackages" value = "to false" /> 
            <-! whether to add the model structure function -> 
            < Property name = "constructorBased" value = "to true" /> 
            <-! whether the data type is CHAR type column trim operation -> 
            < Property name = "trimStrings" value = "to true" / > 
            <! - whether the establishment of Model object that is generated by the Model immutable object does not have a setter method, constructor only -> 
            <property name="immutable"value = "to false" /> 
        </ javaModelGenerator > 

        <-! directory mapping files generated Mapper where each database table corresponding to the generated file SqlMap -> 
        < sqlMapGenerator targetPackage = "com.ldf.shrioDemo.mapper" 
                         targetProject = "src / main / the Java" > 
            < Property name = "enableSubPackages" value = "false" /> 
        </ sqlMapGenerator > 

        <-! client code, generate easy for Model objects and XML configuration file using the code 
                type = "ANNOTATEDMAPPER", and generate Java Model-based annotation objects Mapper 
                type = "MIXEDMAPPER",Generated annotation-based Java Model objects and corresponding Mapper 
                type = "XMLMAPPER",SQLMap XML file and generate separate Mapper Interface 
        -> 
        < javaClientGenerator targetPackage = "com.ldf.shrioDemo.mapper" 
                             targetProject = "the src / main / Java" type = "XMLMAPPER" > 
            < Property name = "enableSubPackages" value = "to true" /> 
        </ javaClientGenerator > 

        <-! tableName: table name is specified 
            domainObjectName: specifies the name of the entity class 
        -> 
        < table tableName = "User" domainObjectName = "User"
               enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false">
        </table>


    </context>
</generatorConfiguration>

Configure four pairs of generator

 

 

 

 Name: give a name to the reverse engineering

command line: command-line commands fixed:

mybatis-generator:generate -e

5 Click Run

 

Guess you like

Origin www.cnblogs.com/liu1275271818/p/11484328.html