1. 程式人生 > >mybatis generator 用法

mybatis generator 用法

maven -o ntb key conn path dbcc odi table

<?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>
    <!--這裏是connector的jar所在的絕對路徑-->
    <classPathEntry
            
location="/Users/zhenghao/.m2/repository/mysql/mysql-connector-java/5.1.39/mysql-connector-java-5.1.39.jar"/> <!--id 必填, defaultModelType是Model的類型,flat不會產生Example,Key,WithBLOB等--> <context id="my" defaultModelType="flat" targetRuntime="MyBatis3"> <commentGenerator> <
property name="suppressDate" value="false"/> <property name="suppressAllComments" value="true"/> </commentGenerator> <!--數據庫連接串--> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/oms?useSSL=false"
userId="root" password="1100131943"/> <!--models--> <javaModelGenerator targetPackage="com.rxhui.oms.core.domain" targetProject="/Users/zhenghao/git/quant-oms/core/src/main/java"> <property name="enableSubPackages" value="true"/> <property name="trimStrings" value="true"/> </javaModelGenerator> <!--xmlMappers--> <sqlMapGenerator targetPackage="mappers" targetProject="/Users/zhenghao/git/quant-oms/core/src/main/resources"> <property name="enableSubPackages" value="true"/> </sqlMapGenerator> <!--DAO--> <javaClientGenerator targetPackage="com.rxhui.oms.core.dao" targetProject="/Users/zhenghao/git/quant-oms/core/src/main/java" type="XMLMAPPER"> <property name="enableSubPackages" value="true"/> </javaClientGenerator> <!--<table tableName="T_FEE_AGTBILL" domainObjectName="FeeAgentBill" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>--> <table tableName="orderEntrust" domainObjectName="OrderEntrust" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> <!--<columnRenamingRule searchString="^D_" replaceString=""/>--> </table> <table tableName="orderCancel" domainObjectName="OrderCancel" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> <!--<columnRenamingRule searchString="^D_" replaceString=""/>--> </table> <table tableName="dealPush" domainObjectName="DealPush" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> <!--<columnRenamingRule searchString="^D_" replaceString=""/>--> </table> </context> </generatorConfiguration>

如果使用maven,

<plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>${mybatis-generator}</version>
                <configuration>
                    <configurationFile>src/main/resources/mybatis-generator/generatorConfig.xml</configurationFile>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
                <executions>
                    <execution>
                        <id>Generate MyBatis Artifacts</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.mybatis.generator</groupId>
                        <artifactId>mybatis-generator-core</artifactId>
                        <version>${mybatis-generator}</version>
                    </dependency>
                </dependencies>
            </plugin>

另外,生成的mapper.xml中,insert如果有默認值(如自增序列或創建時間等),需要使用insertSelective才能正確插入默認值。

mybatis generator 用法