欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

詳解mybatis.generator配上最新的mysql8.0.11的一些坑

一、簡(jiǎn)介

成都創(chuàng)新互聯(lián)公司2013年至今,先為潛山等服務(wù)建站,潛山等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢(xún)服務(wù)。為潛山企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問(wèn)題。

詳解mybatis.generator配上最新的mysql 8.0.11的一些坑

mybatis-geneator是一款mybatis自動(dòng)代碼生成工具,可以通過(guò)配置,自動(dòng)生成Entity、mapper和xml文件。

二、配置(配置的話(huà)  按著我這個(gè)來(lái)配置吧 !  )

在pom文件的<build>下的<plugins>添加以下配置

<plugin>
  <groupId>org.mybatis.generator</groupId>
  <artifactId>mybatis-generator-maven-plugin</artifactId>
  <version>1.3.5</version>
  <configuration>
    <configurationFile>
      <!--這里是配置generatorConfig.xml的路徑       
    不寫(xiě)默認(rèn)在resources目錄下找generatorConfig.xml文件      
     -->
    </configurationFile>
    <verbose>true</verbose>
    <overwrite>true</overwrite>
  </configuration>
  <dependencies>
    <dependency>
      <groupId>MySQL</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.11</version>
    </dependency>
  </dependencies>
</plugin>

 再在resources下創(chuàng)建generatorConfig.xml

詳解mybatis.generator配上最新的mysql 8.0.11的一些坑

配置的信息如下

<?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:起個(gè)名字 -->
  <!-- targetRuntime:設(shè)置生成的文件適用于那個(gè) mybatis 版本 -->
  <context id="default" targetRuntime="MyBatis3">
    <!--optional,旨在創(chuàng)建class時(shí),對(duì)注釋進(jìn)行控制-->
    <commentGenerator>
      <property name="suppressDate" value="true" />
      <!-- 是否去除自動(dòng)生成的注釋 true:是 : false:否 -->
      <property name="suppressAllComments" value="true" />
    </commentGenerator>
    <!--jdbc的數(shù)據(jù)庫(kù)連接-->
    <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"         
    connectionURL="jdbc:mysql://localhost:3306/ajyl_medical_model?serverTimezone=UTC"            userId="root"            password="123456"></jdbcConnection>
    <!--非必須,類(lèi)型處理器,在數(shù)據(jù)庫(kù)類(lèi)型和java類(lèi)型之間的轉(zhuǎn)換控制-->
    <javaTypeResolver>
      <!-- 默認(rèn)情況下數(shù)據(jù)庫(kù)中的 decimal,bigInt 在 Java 對(duì)應(yīng)是 sql 下的 BigDecimal 類(lèi) -->
      <!-- 不是 double 和 long 類(lèi)型 -->
      <!-- 使用常用的基本類(lèi)型代替 sql 包下的引用類(lèi)型 -->
      <property name="forceBigDecimals" value="false" />
    </javaTypeResolver>
    <!-- targetPackage:生成的實(shí)體類(lèi)所在的包 -->
    <!-- targetProject:生成的實(shí)體類(lèi)所在的硬盤(pán)位置 -->
    <javaModelGenerator targetPackage="com.ajyl.modules.asset.entity"     
          targetProject="src/main/java">
      <!-- 是否允許子包 -->
      <property name="enableSubPackages" value="false" />
      <!-- 是否對(duì)modal添加構(gòu)造函數(shù) -->
      <property name="constructorBased" value="true" />
      <!-- 是否清理從數(shù)據(jù)庫(kù)中查詢(xún)出的字符串左右兩邊的空白字符 -->
      <property name="trimStrings" value="true" />
      <!-- 建立modal對(duì)象是否不可改變 即生成的modal對(duì)象不會(huì)有setter方法,只有構(gòu)造方法 -->
      <property name="immutable" value="false" />
    </javaModelGenerator>
    <!-- targetPackage 和 targetProject:生成的 mapper 文件的包和位置 -->
    <sqlMapGenerator targetPackage="mapper"      
       targetProject="src/main/resource">
      <!-- 針對(duì)數(shù)據(jù)庫(kù)的一個(gè)配置,是否把 schema 作為字包名 -->
      <property name="enableSubPackages" value="false" />
    </sqlMapGenerator>
    <!-- targetPackage 和 targetProject:生成的 interface 文件的包和位置 -->
    <javaClientGenerator type="XMLMAPPER"    
           targetPackage="com.ajyl.modules.asset.dao" targetProject="src/main/java">
      <!-- 針對(duì) oracle 數(shù)據(jù)庫(kù)的一個(gè)配置,是否把 schema 作為字包名 -->
      <property name="enableSubPackages" value="false" />
    </javaClientGenerator>
    <table tableName="asset_product_feedback" domainObjectName="AssetProductFeedback"   
     enableCountByExample="false" enableUpdateByExample="false"   
     enableDeleteByExample="false" enableSelectByExample="false"  
      selectByExampleQueryId="false"></table>
  </context>
</generatorConfiguration>

(復(fù)制走改改就好!  )

這里提一下要注意的地方??!

因?yàn)橛玫氖莔ysql-8.0.11

所以配置有所不同  

相信你們用8.0.11啟動(dòng)項(xiàng)目連接數(shù)據(jù)庫(kù)的時(shí)候就遇到過(guò)了

主要就是新版本有新特性,首先,最新官方支持將com.mysql.jdbc.Driver改為com.mysql.cj.jdbc.Driver,此外mysql8.0是不需要建立ssl連接的,你需要顯示關(guān)閉,即url中的useSSL=false;最后你需要設(shè)置CST,CST可視為美國(guó)、澳大利亞、古巴或中國(guó)的標(biāo)準(zhǔn)時(shí)間。serverTimezone是設(shè)置時(shí)區(qū)的,大家可以查一下相關(guān)資料了解一下哦!。

詳解mybatis.generator配上最新的mysql 8.0.11的一些坑

這樣一配置 就成功了  現(xiàn)在我們來(lái)測(cè)試一下  吧!

在右側(cè)打開(kāi)maven面板在Plugin下打開(kāi)Mybatis-generator下的mybatis-generator:fenerate

右鍵Run它!

詳解mybatis.generator配上最新的mysql 8.0.11的一些坑

配置沒(méi)錯(cuò)就會(huì)一路啟動(dòng)成功   entity mapper xml都已經(jīng)生成好了 

詳解mybatis.generator配上最新的mysql 8.0.11的一些坑

看看生成的文件

詳解mybatis.generator配上最新的mysql 8.0.11的一些坑

已經(jīng)成功了  ?。。。c(diǎn)個(gè)贊吧?。?/p>

再來(lái)說(shuō)說(shuō)    遇到的一些問(wèn)題吧!

詳解mybatis.generator配上最新的mysql 8.0.11的一些坑

報(bào)錯(cuò)的代碼

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.581 s
[INFO] Finished at: 2018-08-05T11:51:49+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.5:generate (default-cli) on project smart-campus: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support. -> [Help 1]
[ERROR] [
ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Process finished with exit code 1

拉到后面看報(bào) to use a more specifc time zone value if you want to utilize time zone support. ->

說(shuō)沒(méi)有給他使用時(shí)區(qū)   請(qǐng)給他設(shè)置一個(gè)具體的時(shí)區(qū)值

我們就得在connectionURL的配置上加        ?serverTimezone=UTC

詳解mybatis.generator配上最新的mysql 8.0.11的一些坑

加上就可以解決了   

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。

新聞名稱(chēng):詳解mybatis.generator配上最新的mysql8.0.11的一些坑
網(wǎng)頁(yè)地址:http://chinadenli.net/article34/ihchpe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作、全網(wǎng)營(yíng)銷(xiāo)推廣小程序開(kāi)發(fā)、網(wǎng)站策劃網(wǎng)站內(nèi)鏈、網(wǎng)站排名

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化