Use mybatis-generator in Java polymerization in engineering

Reference Address:

Maven constructed using Java polymeric engineering, the following structure:

 

 Use mybatis-generator can create pojo, mapper, so we put the configuration file foodie-dev-mapper of the folder

1, first configuration for pom.xml introduced mybatis-generator associated jar package

<! - The following is used to configure the mybatis.generator -> 
    <Build> 
        <a finalName> Foodie-dev-Mapper </ a finalName> 
        <the pluginManagement> <! - Lock Down plugins versions to Avoid the using Maven Defaults (On May BE to parent POM Moved) -> 
            <plugins> 
                <-! geelynote Maven plug-core plug of -complier the default compiler supports only the Java 1.4 , and therefore need to add support for high version jre configuration, coupled with the increase in pom.xml inside compile widget -> 
                <plugin> 
                    <the groupId> org.apache.maven.plugins </ the groupId> 
                    <the artifactId> compiler-Maven-plugin </ the artifactId> 
                    <Configuration> 
                        <Source>1.8</source>
                        <target> 1.8 </ target> 
                        <encoding> UTF- 8 </ encoding> 
                        <-! After the Alipay jar package into this position, so that when we mutation, it can be introduced jart package; 
                        otherwise, can be local, but later released, jar packets are missing -> 
                        <compilerArguments> 
                            <extdirs> $ project.basedir} {/ the src / main / the webapp / the WEB-INF / lib </ extdirs> 
                        </ compilerArguments> 
                    </ Configuration> 
                </ plugin> 
                <plugin> 
                    <the artifactId> Clean-Maven-plugin </ the artifactId>
                    <version>3.1.0</version>
                </plugin>
                <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>3.0.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                </plugin>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.1</version>
                </plugin>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>3.2.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>2.5.2</version>
                </plugin>
                <plugin>
                    <the artifactId> Maven-Deploy-plugin </ the artifactId> 
                    <Version> 2.8 . 2 </ Version> 
                </ plugin> 
            </ plugins> 
        </ the pluginManagement> 
        <plugins> 
            <-! table according to the data structure of the database, the configuration of structure, to generate a file for the layer we dao -> 
            <plugin> 
                <the groupId> org.mybatis.generator </ the groupId> 
                <the artifactId> MyBatis-Generator-Maven-plugin </ the artifactId> 
                <Version> 1.3 . 2 </ Version> 
                <Configuration> 
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
            </plugin>
        </plugins>
    </build>

2, a generatorConfig.xml configuration, which is mybatis-generator configuration file

 

 

<? 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 " > 

<-! this profile is used to mybatis-generator -> 
<generatorConfiguration> 
    <-! import property configuration -> 
    <properties Resource = " datasource.properties " > </ Properties> 

    <-! specify a particular database jdbc jar package driving position -> 
    <classPathEntry location="${db.driverLocation}"/> 

    <Context the above mentioned id = " default " targetRuntime = " MyBatis 3 " > 

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

        <-! JDBC database connection -> 
        <jdbcConnection
                driverClass="db.driverClassName} {$ " 
                the connectionURL = " $ {} db.URL " 
                the userId = " $ {} db.username " 
                password = " $ {} db.Password " > 
        </ JdbcConnection> 


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


        <!-  the model model generator,Class used to generate the key contains the primary key of the record class, and class inquiry Example
            the package name targetPackage specify where the generated model generation
            targetProject specify the path where under the project
         -> 
        <-! <javaModelGenerator targetPackage = " com.mmall.pojo " targetProject = " \ src \ main \ the Java. " > -> 
        <javaModelGenerator targetPackage = " com.zb .pojo " targetProject = " ./src/main/java " > 
            <-! whether to allow sub-packet, i.e. targetPackage.schemaName.tableName -> 
            <Property name = " enableSubPackages " value = " to false " /> 
            <-! Are adding to model constructor ->
            <property name=" constructorBased " value = " to true " /> 
            <! - whether the data type is CHAR type column trim operation -> 
            <Property name = " trimStrings " value = " to true " /> 
            <-! Model object to establish whether that is generated by the Model immutable object does not have a setter method, constructor only -> 
            <Property name = " immutable " value = " false " /> 
        </ javaModelGenerator> 

        <!--mapper generated map file directory where a database table to generate each of the corresponding file SqlMap -> 
        <-! <sqlMapGenerator targetPackage = " by mappers " targetProject=".\src\main\resources">-->
        <sqlMapGenerator targetPackage="mappers" targetProject="./src/main/resources">
            <property name="enableSubPackages" value="false"/>
        </sqlMapGenerator>
        
        <!-- targetPackage:mapper接口dao生成的位置 -->
        <!--<javaClientGenerator type="XMLMAPPER" targetPackage="com.mmall.dao" TargetProject = " . \ Src \ main \ the Java " > -> 
        <javaClientGenerator of the type = " XMLMAPPER " targetPackage = " com.zb.dao " targetProject = " ./src/main/java " > 
            <- enableSubPackages!: whether to allow schema as the package suffix -> 
            <Property name = " enableSubPackages " value = " false " /> 
        </ javaClientGenerator> 


<-! this is used to configure the database files and generated files -> 
<! - tableName is the database table name -> 
<!- domainObjectName we generated pojo name -> 
        <table tableName = " STU " domainObjectName = " Stu " enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="carousel" domainObjectName="Carousel" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="category" domainObjectName="Category" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="items" domainObjectName="Items" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="items_comments" domainObjectName="ItemsComments" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="items_img" domainObjectName="ItemsImg" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="items_param" domainObjectName="ItemsParam" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="items_spec" domainObjectName="ItemsSpec" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="order_items" domainObjectName="OrderItems" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="order_status" domainObjectName="OrderStatus" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="orders" domainObjectName="Orders" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="user_address" domainObjectName="UserAddress" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="users" domainObjectName="Users" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <!-- geelynote mybatis插件的搭建 -->
    </context>
</generatorConfiguration>

Remarks:

 

 Folder name and configuration file must be consistent

3, click on the right maven code generation tools

 

 4, to be used in the polymerization to generate the project file, mybaitis also need to be arranged in the application.yml

mybatis:
  mapper-locations: classpath*:mappers/*.xml

This is necessary, otherwise there will be operating mapper and xml do not match

Guess you like

Origin www.cnblogs.com/zhaobao1830/p/12199123.html