• 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即可

  • 相关阅读:
    Moodle 3.8 安装过程
    Discourse 数据分发
    Moodle 安装的时候提示 original IP
    Apache 安装运行测时候提示错误 (13)Permission denied: AH00091: httpd: could not open error log file
    Apache 配置 SELinux 命令的时候的命令 semanage
    Apache Httpd 安装 AH00558错误
    Discourse 如何修改用户自己的密码
    Discourse 如何限制注册用户的密码长度
    Discourse 的快捷键列表
    S3 存储附件和图片无法上传
  • 原文地址:https://www.cnblogs.com/it-taosir/p/10345811.html
Copyright © 2020-2023  润新知