mybatis-generator plugin

First, be sure to have mybatis dependence

        <!--mybatis spring-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.2</version>
        </dependency>

And generate code to mybatis dependent core

         <!--mybatis生成代码控件-->
        <dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
            <version>1.3.2</version>
        </dependency>

After the required MySQL depends

        <!--MySQL依赖-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>

After the need to add a plugin in the build> plugins

<!--mybatis generator plugin-->
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>
                <executions>
                    <execution>
                        <id>Generate MyBatis Files</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <phase>generate-sources</phase>
                        <configuration>
                            <verbose>true</verbose>
                            <overwrite>true</overwrite>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>5.1.38</version>
                    </dependency>
                    <dependency>
                        <groupId>org.mybatis.generator</groupId>
                        <artifactId>mybatis-generator-core</artifactId>
                        <version>1.3.5</version>
                    </dependency>
                    <dependency>
                        <groupId>org.mybatis</groupId>
                        <artifactId>mybatis</artifactId>
                        <version>3.4.2</version>
                    </dependency>
                </dependencies>
            </plugin>
            <!--/mybatis generator plugin-->
Intelli IDEA in the menu bar, click on RUN-Edit Configurations, click the top left corner of the pop-up window + sign to add Maven. Configure a name for the current, here named "generator",
Then enter the "Command line" options " the mybatis-Generator: the Generate -e ." Here plus the "-e" option is to allow the plug-in output detailed information to help us locate the problem.
Click Apply.
Configuration files in the classpath:
<? 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 > 

    < context ID =" DB2Tables "     targetRuntime =" MyBatis 3 " > 
        <-! avoid repetition code generation widget -> 
        < plugin type =" com.tansuo365.test1. util.OverIsMergeablePlugin "  /> 

        <-! whether comments in the code -> 
        <commentGenerator>
            <property name = "suppressDate" value = "to true"  /> 
            < Property name = "suppressAllComments" value = "to true"  /> 
        </ commentGenerator > 

        <-! database account password link address -> 
        < JdbcConnection driverClass = "com.mysql .cj.jdbc.Driver " connectionURL =" jdbc: MySQL: // localhost: 3306 / tansuodb " userId =" root " password =" xxxxxxxx " > 
        </ JdbcConnection > 
        ! <- I do not know what to do with. . . Anyway Tieshanglai ~ -> 
        <
            name="forceBigDecimals" value="false"/>
        </javaTypeResolver>
        <!--生成bean类存放位置-->
        <javaModelGenerator targetPackage="com.tansuo365.test1.bean" targetProject="src">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>
        <!--生成xml映射文件存放位置-->
        <sqlMapGenerator targetPackage="classpath:mappings" targetProject="resources">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>
        <!--生成mapper类存放位置-->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.tansuo365.test1.mapper" targetProject="src">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>

        <->generating a corresponding table and the class name<! -
        table tableName="petroleum_coke_tbl" domainObjectName="PetroleumCoke" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="true" selectByExampleQueryId="false">
            <property name="my.isgen.usekeys" value="true"/>
            <property name="useActualColumnNames" value="true"/>
            <generatedKey column="id" sqlStatement="JDBC"/>
        </table>
     <!--   <table tableName="role" domainObjectName="Role" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="true" selectByExampleQueryId="false">
            <property name="my.isgen.usekeys" value="true"/>
            <property name="useActualColumnNames" value="true"/>
            <generatedKey column="id" sqlStatement="JDBC"/>
        </table>
        <table tableName="permission" domainObjectName="Permission" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="true" selectByExampleQueryId="false">
            <property name="my.isgen.usekeys" value="true"/>
            <property name="useActualColumnNames" value="true"/>
            <generatedKey column="id" sqlStatement="JDBC"/>
        </table>
        <table tableName="user_role" domainObjectName="UserRole" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="true" selectByExampleQueryId="false">
            <property name="my.isgen.usekeys" value="true"/>
            <property name="useActualColumnNames" value="true"/>
            <generatedKey column="id" sqlStatement="JDBC"/>
        </table>
        <table tableName="role_permission" domainObjectName="RolePermission" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="true" selectByExampleQueryId="false">
            <property name="my.isgen.usekeys" value="true"/>
            <property name="useActualColumnNames" value="true"/>
            <generatedKey column="id" sqlStatement="JDBC"/>
        </table>-->

    </context>
</generatorConfiguration>

Specific reference may be https://www.jianshu.com/p/310c299846fc




Guess you like

Origin www.cnblogs.com/ukzq/p/11272003.html