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 右键运行即可

  • 相关阅读:
    flutter doctor出现问题 [!] Android toolchain
    CSS中的cursor属性
    致蝙蝠侠阿卡姆三部曲——最伟大的改编游戏
    ajax的使用:例题、ajax的数据处理
    用ajax对数据进行删除和查看
    ThinkPhp框架:验证码功能
    ThinkPhp框架:父类及表单验证
    ThinkPhp框架:分页查询和补充框架知识
    ThinkPhp框架对“数据库”的基本操作
    ThinkPHP框架知识的注意点
  • 原文地址:https://www.cnblogs.com/xd502djj/p/10300693.html
Copyright © 2011-2022 走看看