SpringBoot中使用mybatis-generator自動生產

來源:互聯網
上載者:User

標籤:str   mave   nts   end   blank   ble   cut   csdn   自動   

步驟:

1.在pom.xml中添加外掛程式配置

<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.39</version>                    </dependency>                    <dependency>                        <groupId>org.mybatis.generator</groupId>                        <artifactId>mybatis-generator-core</artifactId>                        <version>1.3.5</version>                    </dependency>                </dependencies>                <executions>                    <execution>                        <id>Generate MyBatis Artifacts</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>

2.在resources檔案夾中添加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>    <context id="DB2Tables" targetRuntime="MyBatis3">        <commentGenerator>            <property name="suppressDate" value="true"/>            <property name="suppressAllComments" value="true"/>        </commentGenerator>        <!--資料庫連結地址帳號密碼-->        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/longhubang" userId="root" password="hongda$123456">        </jdbcConnection>        <javaTypeResolver>            <property name="forceBigDecimals" value="false"/>        </javaTypeResolver>        <!--產生Model類存放位置-->        <javaModelGenerator targetPackage="com.example.scheduleService.model" targetProject="src/main/java">            <property name="enableSubPackages" value="true"/>            <property name="trimStrings" value="true"/>        </javaModelGenerator>        <!--產生對應檔存放位置-->        <sqlMapGenerator targetPackage="com.example.scheduleService.mapper" targetProject="src/main/java">            <property name="enableSubPackages" value="true"/>        </sqlMapGenerator>        <!--產生Dao類存放位置-->        <!-- 用戶端代碼,產生便於使用的針對Model對象和XML設定檔 的代碼                type="ANNOTATEDMAPPER",產生Java Model 和基於註解的Mapper對象                type="MIXEDMAPPER",產生基於註解的Java Model 和相應的Mapper對象                type="XMLMAPPER",產生SQLMap XML檔案和獨立的Mapper介面        -->        <javaClientGenerator type="ANNOTATEDMAPPER" targetPackage="com.example.scheduleService.dao" targetProject="src/main/java">            <property name="enableSubPackages" value="true"/>        </javaClientGenerator>        <!--產生對應表及類名-->        <!--<table tableName="stocktradeinfo" domainObjectName="StockTradeInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>-->        <table tableName="theme" domainObjectName="Theme" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>        <table tableName="stockTheme" domainObjectName="StockTheme" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>    </context></generatorConfiguration>

3.根據配置建立對應的model,mapper,dao檔案夾

4.使用maven中的mybatis-generator:generate根據資料庫裡面表生產相關的類,Mapper

注意:

這裡面自動生產的Mapper

1.沒有@Mapper註解

2.在insert的時候會帶上主鍵ID

 

http://blog.csdn.net/yezhuanxu/article/details/53483130

SpringBoot中使用mybatis-generator自動生產

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.