springboot實現mybaitis逆向工程

springboot實現mybaitis逆向工程

  1. 首先引入依賴,一共需要兩個依賴(一個是mybaits依賴,一個是mybatis逆向工程插件)
		<dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.3</version>
        </dependency>
        <!--   Mybatis逆向工程插件     -->
         <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.7</version>
                <configuration>
                    <overwrite>true</overwrite>                    										<configurationFile>
                    src/main/resources/generator/generatorConfig.xml
                    </configurationFile>
                </configuration>
        </plugin>
  1. 然後在resource目錄下新建generator文件夾,在generator文件夾創建一個generatorConfig.xml文件,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>
    <!-- 數據庫驅動:選擇你的本地硬盤上面的數據庫驅動包-->
    <classPathEntry location="F:\LocalRepository\mysql\mysql-connector-java\8.0.20\mysql-connector-java-8.0.20.jar"/>
    <context id="DB2Tables" targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressDate" value="true"/>
            <!--   去除自動生成的註釋         -->
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>
        <!--數據庫鏈接URL,用戶名、密碼 -->
        <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/fly?characterEncoding=UTF-8&amp;useSSL=true&amp;serverTimezone=UTC"
                        userId="root"
                        password="123">
        </jdbcConnection>
        <!-- 類型轉換 -->
        <javaTypeResolver>
            <!-- 是否使用bigDecimal,
                false: 把JDBC DECIMAL 和 NUMERIC 類型解析爲 Integer(默認)
                true:  把JDBC DECIMAL 和 NUMERIC 類型解析爲java.math.BigDecimal
            -->
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>
        <!-- 生成模型的包名和位置-->
        <javaModelGenerator targetPackage="com.itguigu.demo1.bean" targetProject="src/main/java">
            <!-- 默認false 是否允許子包 -->
            <property name="enableSubPackages" value="true"/>
            <!-- 默認false 是否對類CHAR類型的列的數據進行trim操作 -->
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>
        <!-- 生成映射文件的包名和位置-->
        <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>
        <!-- 生成DAO的包名和位置-->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.itguigu.demo1.dao" targetProject="src/main/java">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>
        <!-- 要生成的表 tableName是數據庫中的表名或視圖名 domainObjectName是實體類名-->
        <!-- <table tableName="risk_model_order" domainObjectName="DSRiskModelOrder" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
         <table tableName="tel_bill_record" domainObjectName="DSTelBillRecord" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>-->
        <table tableName="t_corp"
               enableCountByExample="false"
               enableUpdateByExample="false"
               enableDeleteByExample="false"
               enableSelectByExample="false"
               selectByExampleQueryId="false">
        </table>
    </context>
</generatorConfiguration>
  1. 點擊右側maven插件,生成mapper,dao,bean文件
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章