springboot 多了8小时_spring boot项目时间字段少8小时问题

今天发现我的工程很多数据保存后到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然后都正常了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值