zoukankan      html  css  js  c++  java
  • springboot 配置mysql日期返回格式

    默认情况下json时间格式带有时区,并且是世界标准时间,和我们的时间差了八个小时
    在application.properties中设置

     

    #返回json的全局时间格式
    spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
    spring.jackson.time-zone=GMT+8

    修改前

     修改后

    jdbc配置

    application.properties 配置文件中添加 MySQL 数据库的相关配置:

    mysql5

    #mysql数据库连接
    spring.datasource.driver-class-name=com.mysql.jdbc.Driver
    spring.datasource.url=jdbc:mysql://localhost:3306/stu
    spring.datasource.username=root
    spring.datasource.password=123456

    mysql8以上(spring boot 2.1)

    注意:driver和url的变化

    spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
    spring.datasource.url=jdbc:mysql://localhost:3306/stu?serverTimezone=GMT%2B8
    spring.datasource.username=root
    spring.datasource.password=123456

    注意:

    1、这里的 url 使用了 ?serverTimezone=GMT%2B8 后缀,因为Spring Boot 2.1 集成了 8.0版本的jdbc驱动,这个版本的 jdbc 驱动需要添加这个后缀,否则运行测试用例报告如下错误:

    java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more

    2、这里的 driver-class-name 使用了 com.mysql.cj.jdbc.Driver ,在 jdbc 8 中 建议使用这个驱动,之前的 com.mysql.jdbc.Driver 已经被废弃,否则运行测试用例的时候会有 WARN 信息

      

     

  • 相关阅读:
    TinyXML 2.4.2发布
    OpenAL 1.1 Release
    Microsoft ship Visual Studio 2005 and .NET 2.0
    Boost中文站
    第一次Blog
    POJ3020 Antenna Placement 二分图匹配+拆点构图
    SGU438 The Glorious Karlutka River =) 最大流(动态流问题)
    HDU2732 Leapin' Lizards 最大流
    SGU176 Flow construction 有上下界的最小流
    POJ1459 Power Network 网络流
  • 原文地址:https://www.cnblogs.com/konglxblog/p/14642586.html
Copyright © 2011-2022 走看看