spring boot项目时间字段少8小时问题


本文摘自classinstance.cn。

今天发现我的工程很多数据保存后到mysql,创建时间字段都少了8小时,看了下其他微服务兄弟项目的数据,都不会有问题,然后才发现别的项目在连接mysql的url上有加上时区+8小时的配置,如下:

spring:
  datasource:
    name: mysql_test
    type: com.alibaba.druid.pool.DruidDataSource
    #druid相关配置
    druid:
      #监控统计拦截的filters
      filters: stat
      #driver-class-name: com.mysql.cj.jdbc.Driver
      driver-class-name: com.mysql.jdbc.Driver
      #基本属性
      url: jdbc:mysql://xxxxxx:3306/sysbase?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2b8
      username: root
      ....

我把连接配置改成:

jdbc:mysql://xxxx:3306/sysbase?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2b8

就发现保存数据到mysql时间字段正常了。

但是通过springmvc查询显示到jsp页面中时又少了8小时。

后来想想应该是要设置json转换时间的时区,配置如下:

spring:
  profiles:
    active: dev
  jackson:
    date-format: yyyy-MM-dd HH🇲🇲ss
    joda-date-time-format: yyyy-MM-dd HH🇲🇲ss
    time-zone: GMT+8

然后都正常了。

相关阅读 >>

spring boot多module项目导入eclipse

spring boot项目引入jar包时启动报错:java.lang.stackoverflowerror

如何实现生产环境关闭swagger,只有开发环境中开启swagger

spring boot跨域配置

spring boot项目时间字段少8小时问题

更多相关阅读请进入《spring boot》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...