码迷,mamicode.com
首页 > 其他好文 > 详细

mybatis generator 用法

时间:2018-07-06 22:23:24      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:source   efault   resource   jdbc   column   query   nbsp   tab   cli   

<?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 用法

标签:source   efault   resource   jdbc   column   query   nbsp   tab   cli   

原文地址:https://www.cnblogs.com/ppgeneve/p/9275622.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!