zoukankan      html  css  js  c++  java
  • mybatis-generator自动生成代码工具

    1.在项目的配置文件中放入配置文件mybatis-generator-config.xml   根据情况修改下配置

    <?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>
    
        <!-- !!!! Driver Class Path !!!! -->
        <classPathEntry location="/Users/dongjunjie/.m2/repository/mysql/mysql-connector-java/5.1.38/mysql-connector-java-5.1.38.jar"/>
    
    
        <context id="context" targetRuntime="MyBatis3">
            <plugin type="org.mybatis.generator.plugins.CaseInsensitiveLikePlugin" />
            <commentGenerator>
                <property name="suppressAllComments" value="true"/>
                <property name="suppressDate" value="true"/>
            </commentGenerator>
    
            <!-- !!!! Database Configurations !!!! -->
            <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://****/exchange?characterEncoding=utf-8"
                            userId="exchange" password="****"/>
    
            <javaTypeResolver>
                <property name="forceBigDecimals" value="false"/> </javaTypeResolver>
    
            <!-- !!!! Model Configurations !!!! -->
            <javaModelGenerator targetPackage="com.cmcm.finance.wallet.sync.entity" targetProject="/Users/dongjunjie/IdeaProjects/wallet-sync/src/main/java">
                <property name="enableSubPackages" value="true"/>
                <property name="trimStrings" value="true"/>
            </javaModelGenerator>
    
            <!-- !!!! Mapper XML Configurations !!!! -->
            <sqlMapGenerator targetPackage="sqlmapper" targetProject="/Users/dongjunjie/IdeaProjects/wallet-sync/src/main/java/com/*/finance/wallet/sync/dao">
                <property name="enableSubPackages" value="true"/>
            </sqlMapGenerator>
    
            <!-- !!!! Mapper Interface Configurations !!!! -->
            <javaClientGenerator targetPackage="com.*.finance.wallet.sync.dao" targetProject="/Users/dongjunjie/IdeaProjects/wallet-sync/src/main/java" type="XMLMAPPER">
                <property name="enableSubPackages" value="true"/>
            </javaClientGenerator>
    
            <!-- !!!! Table Configurations !!!! -->
            <table tableName="distribute_coin_detail" domainObjectName="DistributeCoinDetail" enableCountByExample="true" enableDeleteByExample="true" enableSelectByExample="true"
                   enableUpdateByExample="true"/>
    
        </context>
    </generatorConfiguration>

    2. 添加maven 任务

     Edit-Configurations ->name  、work directory、Command line (mybatis-generator:generate -e )

     3. pom 文件中添加 build  -plugin 

     <plugin>
                    <groupId>org.mybatis.generator</groupId>
                    <artifactId>mybatis-generator-maven-plugin</artifactId>
                    <version>1.3.2</version>
                    <configuration>
                        <configurationFile>src/main/resources/dev/mybatis-generator-config.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>1.3.2</version>
                        </dependency>
                    </dependencies>
                </plugin>

    4. 运行maven的自动生成插件 

        run-config 》 mybatis-gen -》右键 run 

       pom中添加Plugins 也可以在idea的maven project中 的Plugins中找到mybatis-generater 右键运行即可

  • 相关阅读:
    [LeetCode]130 Surrounded Regions(DFS)
    [LeetCode]233 Number of Digit One(数位DP)
    POJ 3225.Help with Intervals-线段树(成段替换、区间异或、简单hash)
    POJ 2528.Mayor's posters-线段树(成段替换、离散数据、简单hash)
    POJ 3468.A Simple Problem with Integers-线段树(成段增减、区间查询求和)
    HDU 1698.Just a Hook-线段树(成段替换、输出总和tree[1])
    POJ 2886.Who Gets the Most Candies? -线段树(单点更新、类约瑟夫问题)
    计蒜客 28437.Big brother said the calculation-线段树+二分-当前第k个位置的数 ( ACM训练联盟周赛 M)
    HDU 5649.DZY Loves Sorting-线段树+二分-当前第k个位置的数
    计蒜客 28449.算个欧拉函数给大家助助兴-大数的因子个数 (HDU5649.DZY Loves Sorting) ( ACM训练联盟周赛 G)
  • 原文地址:https://www.cnblogs.com/xd502djj/p/10300693.html
Copyright © 2011-2022 走看看