zoukankan      html  css  js  c++  java
  • mybatis-generator:generate 生成代码配置踩坑详解

    mybatis-generator:generate 生成代码配置踩坑不少,在此留下笔记以便后续填坑

    一、mysql返回时间问题

    • 错误信息:
    [ERROR] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2:generate (default-cli) on project coisini-mango-server: 
    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]
    

    JDBC需要配置服务器时区值, 在jdbc连接的url后面加上serverTimezone=GMT即可解决问题,如果使用GMT+8时区,需要写成GMT%2B8,如下:

    • application.properties的写法:
    url: jdbc:mysql://localhost:3306/coisini?useUnicode=true&zeroDateTimeBehavior=convertToNull&autoReconnect=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
    
    • generator.xml的写法,注:在xml中写&,会因为未转义而报错要将&写成&
    <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/coisini?serverTimezone=GMT%2B8&amp;useUnicode=true&amp;characterEncoding=utf-8&amp;useSSL=false" userId="root" password="sunday"></jdbcConnection>
    

    二、找不到数据库连接驱动包

    • 错误信息:
    [ERROR] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.2:generate (default-cli)
    on project coisini-mango-server: Execution default-cli of goal org.mybatis.generator:mybatis-generator-maven-
    plugin:1.3.2:generate failed: Exception getting JDBC Driver: com.mysql.cj.jdbc.Driver -> [Help 1]
    

    关于这个异常,网上大多数说在generatorConfig.xml中加入数据库驱动包的绝对路径,
    方法一:

    <classPathEntry  location="G:Program Filesjavaapache-maven-3.6.1
    epositorymysqlmysql-connector-java8.0.13mysql-connector-java-8.0.13.jar"/>
    

    采用绝对路径后,编译会报一个弃用警告

    • 警告信息:
    Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. 
    The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
    

    这里就引出了我们解决找不到数据库连接驱动包的办法,
    方法二:

    • 更改mysql驱动类为com.mysql.cj.jdbc.Driver,application.propertiesgenerator.xml都要改
    • 在pom.xml中plugin节点下添加mysql-connector-java的dependency
    <plugin>
        <groupId>org.mybatis.generator</groupId>
         <artifactId>mybatis-generator-maven-plugin</artifactId>
         <version>1.3.2</version>
         <configuration>
             <configurationFile>src/main/resources/generator/generator.xml</configurationFile>
             <overwrite>true</overwrite>
             <verbose>true</verbose>
         </configuration>
     </plugin>
    

    spring boot本就是通过maven自动配置,这里建议采用方法二,不建议使用配置绝对路径。

    详细代码移步:mybatis 生成代码配置 mybatis-generator:generate 的使用详解


  • 相关阅读:
    ll command not found 当ll无法识别的解决办法
    idea控制台全屏
    查看centos版本号
    java Error: 无法访问org.apache.http.annotation.ThreadSafe 找不到org.apache.http.annotation.ThreadSafe的类文件
    DigestUtils.md5Hex()加密
    JAVA 8 '::' 关键字
    CVE-2020-1472 NetLogon特权提升漏洞
    OpenSSH的scp命令注入漏洞(CVE-2020-15778)
    redis未授权访问漏洞&简单利用&总结
    常见web信息泄露
  • 原文地址:https://www.cnblogs.com/maggieq8324/p/11414694.html
Copyright © 2011-2022 走看看