zoukankan      html  css  js  c++  java
  • Mybatis逆向工程

    Mybatis逆向工程

    前言:之前整理过mybatis-plus的,现在整理下mybatis的,大同小异,本身mybatis-plus就是mybatis的增强版~

    pom.xml文件

    <build>
            <plugins>
                <plugin>
                    <!--Mybatis-generator插件,用于自动生成Mapper和POJO-->
                    <groupId>org.mybatis.generator</groupId>
                    <artifactId>mybatis-generator-maven-plugin</artifactId>
                    <version>1.3.2</version>
                    <configuration>
                        <!--配置文件的位置-->
                        <configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
                        <verbose>true</verbose>
                        <overwrite>true</overwrite>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>mysql</groupId>
                            <artifactId>mysql-connector-java</artifactId>
                            <version>5.1.6</version>
                        </dependency>
                        <dependency>
                            <groupId>org.mybatis.generator</groupId>
                            <artifactId>mybatis-generator-core</artifactId>
                            <version>1.3.2</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>

    generatorConfig.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>
        <context id="DB2Tables" 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/taosir_order"
                            userId="root"
                            password="root">
            </jdbcConnection>
    
            <!--生成实体类 指定包名 以及生成的地址 (可以自定义地址,但是路径不存在不会自动创建  使用Maven生成在target目录下,会自动创建) -->
            <javaModelGenerator targetPackage="cn.zytao.taosir.order.pojo"
                                targetProject="./src/main/java">
                <!--targetProject="/Users/yoan/work/GeetionProjects/ZhongTu_web/src/main/java">-->
                <property name="enableSubPackages" value="false"/>
                <property name="trimStrings" value="true"/>
            </javaModelGenerator>
            <!--生成SQLMAP文件 -->
            <sqlMapGenerator targetPackage="mapper"
                             targetProject="./src/main/resources">
                <!--targetProject="/Users/yoan/work/GeetionProjects/ZhongTu_web/src/main/resources">-->
                <property name="enableSubPackages" value="false"/>
            </sqlMapGenerator>
            <!--生成Dao文件 可以配置 type="XMLMAPPER"生成xml的dao实现  context id="DB2Tables" 修改targetRuntime="MyBatis3"  -->
            <javaClientGenerator type="XMLMAPPER"
                                 targetPackage="cn.zytao.taosir.order.dao"
                                 targetProject="./src/main/java">
                <!--targetProject="/Users/yoan/work/GeetionProjects/ZhongTu_web/src/main/java">-->
                <property name="enableSubPackages" value="false"/>
            </javaClientGenerator>
    
            <table tableName="order"
                   domainObjectName="Order"
                   enableCountByExample="false"
                   enableUpdateByExample="false"
                   enableDeleteByExample="false"
                   enableSelectByExample="false"
                   selectByExampleQueryId="false">
            </table>
            <table tableName="order_delivery"
                   domainObjectName="OrderDelivery"
                   enableCountByExample="false"
                   enableUpdateByExample="false"
                   enableDeleteByExample="false"
                   enableSelectByExample="false"
                   selectByExampleQueryId="false">
            </table>
            <table tableName="order_product"
                   domainObjectName="OrderProduct"
                   enableCountByExample="false"
                   enableUpdateByExample="false"
                   enableDeleteByExample="false"
                   enableSelectByExample="false"
                   selectByExampleQueryId="false">
            </table>
    
        </context>
    </generatorConfiguration>

    配置基本一目了然,根据自己的情况配置即可

    最后maven项目右键

    Run As

    Maven build..

    输入mybatis-generator:generate

    再点击run即可

  • 相关阅读:
    使用SpringAOP获取一次请求流经方法的调用次数和调用耗时
    疫苗之殇与理性应对之道
    【做更好的职场人】理性、弹性、开放的沟通
    使用IntelljIDEA生成接口的类继承图及装饰器模式
    订单导出应对大流量订单导出时的设计问题
    预发和线上的自动化对比工具微框架
    从实战角度看如何构建高质量的软件:一线工程师的一份质量手记
    代码问题及对策
    若干设计经验教训小记
    输入输出无依赖型函数的GroovySpock单测模板的自动生成工具(上)
  • 原文地址:https://www.cnblogs.com/it-taosir/p/10345811.html
Copyright © 2011-2022 走看看