1.确认在配置数据库的URL上加了“serverTimezone”,这样存入数据库时间肯定正确。如下
url: jdbc:mysql://xxx:xx/db?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2B8
2.确认配置jackson的“time-zone”,确保给前端时间正确。这是因为我们使用spring的标签比如@RestController、@JsonFormat,会被Jackson框架转换,如果不设置为东八区(+8),会相差8小时。如下
spring:
jackson:
time-zone: GMT+8

配置数据库URL时添加serverTimezone=GMT+8确保时间存储正确,同时在Spring的Jackson配置中设置time-zone:GMT+8以保证日期时间在JSON转换时不产生8小时偏差。
1784

被折叠的 条评论
为什么被折叠?



