generator.xml mysql_详解mybatis.generator配上最新的mysql 8.0.11的一些坑

本文介绍了如何配置mybatis-generator与MySQL8.0.11进行代码生成,强调了由于MySQL新版本特性导致的配置变化,如驱动类名更改与设置serverTimezone参数为UTC以解决时区问题。在配置完成后,通过maven执行生成操作成功生成了Entity、Mapper和XML文件。文章还分享了在配置过程中遇到的时区识别错误及其解决方案。
摘要由CSDN通过智能技术生成

一、简介

0a10a4a0597cf98a385dfa7aec488776.png

mybatis-geneator是一款mybatis自动代码生成工具,可以通过配置,自动生成Entity、mapper和xml文件。

二、配置(配置的话  按着我这个来配置吧 !  )

在pom文件的下的添加以下配置

org.mybatis.generator

mybatis-generator-maven-plugin

1.3.5

true

true

mysql

mysql-connector-java

8.0.11

再在resources下创建generatorConfig.xml

01a54497e53ff8cf0c3def3c7ea1b61b.png

配置的信息如下

/p>

PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"

"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">

connectionURL="jdbc:mysql://localhost:3306/ajyl_medical_model?serverTimezone=UTC" userId="root" password="123456">

targetProject="src/main/java">

targetProject="src/main/resource">

targetPackage="com.ajyl.modules.asset.dao" targetProject="src/main/java">

enableCountByExample="false" enableUpdateByExample="false"

enableDeleteByExample="false" enableSelectByExample="false"

selectByExampleQueryId="false">

(复制走改改就好!  )

这里提一下要注意的地方啊!

因为用的是mysql-8.0.11

所以配置有所不同

相信你们用8.0.11启动项目连接数据库的时候就遇到过了

主要就是新版本有新特性,首先,最新官方支持将com.mysql.jdbc.Driver改为com.mysql.cj.jdbc.Driver,此外mysql8.0是不需要建立ssl连接的,你需要显示关闭,即url中的useSSL=false;最后你需要设置CST,CST可视为美国、澳大利亚、古巴或中国的标准时间。serverTimezone是设置时区的,大家可以查一下相关资料了解一下哦!。

26dd37d34bd73f873285c19934eed43c.png

这样一配置 就成功了  现在我们来测试一下  吧!

在右侧打开maven面板在Plugin下打开Mybatis-generator下的mybatis-generator:fenerate

右键Run它!

0fca0cf6fab6f6b2bcd47bb70e751732.png

配置没错就会一路启动成功   entity mapper xml都已经生成好了

4837b39160b76a0f77b8c430376dc896.png

看看生成的文件

3fdd04c597fc2c6d612d9096da5193a1.png

已经成功了  !!!(点个赞吧!)

再来说说    遇到的一些问题吧!

83f028674a117cd3c653ccdec01290b1.png

报错的代码

[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

拉到后面看报 to use a more specifc time zone value if you want to utilize time zone support. ->

说没有给他使用时区   请给他设置一个具体的时区值

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

36d40688fdcdb003bb09e624a08ef926.png

加上就可以解决了

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值