在IDEA中使用逆向工程generator

 

目录

一、向pom文件中导入逆向工程的相关插件

二、在resource目录下引入mybatis-generator.xml

三、对IDEA进行配置

1、点击Run------>Edit Configurations

2、点击+号,选择Maven插件

3、编写Name和Commandline

4、运行mybatis-generator

三、异常处理


一、向pom文件中导入逆向工程的相关插件

<plugin>
          <groupId>org.mybatis.generator</groupId>
          <artifactId>mybatis-generator-maven-plugin</artifactId>
          <version>1.3.5</version>
          <dependencies>
            <dependency>
              <groupId>mysql</groupId>
              <artifactId>mysql-connector-java</artifactId>
              <version>5.1.41</version>
            </dependency>
          </dependencies>
          <executions>
            <execution>
              <id>mybatis generator</id>
              <phase>package</phase>
              <goals>
                <goal>generate</goal>
              </goals>
            </execution>
          </executions>
          <configuration>
            <!--允许移动生成的文件-->
            <verbose>true</verbose>
            <!--允许自动覆盖文件-->
            <overwrite>true</overwrite>
            <configurationFile>
              src/main/resources/mybatis-generator.xml
            </configurationFile>
          </configuration>

        </plugin>

二、在resource目录下引入mybatis-generator.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>

    <!--<classPathEntry location="/Program Files/IBM/SQLLIB/java/db2java.zip" />-->


    <context id="DB2Tables" targetRuntime="MyBatis3">
        <commentGenerator>
            <!-- 是否去除自动生成的注释 true:是 : false:否 -->
            <property name="suppressAllComments" value="true" />
        </commentGenerator>
        <!--数据库连接地址账号密码-->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost/miaosha"
                        userId="root"
                        password="123456">
        </jdbcConnection>


        <javaTypeResolver >
            <property name="forceBigDecimals" value="false" />
        </javaTypeResolver>

        <!--生成Model/DataObject类存放的位置-->
        <javaModelGenerator targetPackage="com.miaoshaproject.dataobject" targetProject="src/main/java">
            <property name="enableSubPackages" value="true" />
            <property name="trimStrings" value="true" />
        </javaModelGenerator>

        <!--生成映射文件存放的位置-->
        <sqlMapGenerator targetPackage="mapping"  targetProject="src/main/resources">
            <property name="enableSubPackages" value="true" />
        </sqlMapGenerator>

        <!--生成Dao类存放的位置-->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.miaoshaproject.dao"  targetProject="src/main/java">
            <property name="enableSubPackages" value="true" />
        </javaClientGenerator>


        <!--生成对应表及类名-->
        <table tableName="item" domainObjectName="ItemDO" enableCountByExample="false"
               enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
        selectByExampleQueryId="false"></table>
        <table tableName="item_stock" domainObjectName="ItemStockDO" enableCountByExample="false"
               enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false"></table>
        <table tableName="user_info" domainObjectName="UserDO" enableCountByExample="false"
        enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
        selectByExampleQueryId="false"></table>
        <table tableName="order_info" domainObjectName="OrderDO" enableCountByExample="false"
               enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false"></table>
        <table tableName="promo" domainObjectName="PromoDO" enableCountByExample="false"
               enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false"></table>
        <table tableName="sequence_info" domainObjectName="SequenceDO" enableCountByExample="false"
               enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false"></table>
        <table tableName="user_password" domainObjectName="UserPasswordDO" enableCountByExample="false"
               enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false"></table>



    </context>
</generatorConfiguration>

三、对IDEA进行配置

1、点击Run------>Edit Configurations

2、点击+号,选择Maven插件

3、编写Name和Commandline

4、运行mybatis-generator

三、异常处理

https://blog.csdn.net/qq_41808387/article/details/104392159

发布了129 篇原创文章 · 获赞 9 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_41808387/article/details/104391817