1.数据库连接时serverTimezone为GMT%2B8,查询的时间正常,但到页面显示时,比数据库的时间晚了8个小时
spring.datasource.url=jdbc:mysql://localhost9:3306/test?serverTimezone=GMT%2B8
2.最后发现在实体类中使用了@JsonFormat注解
spring转json的默认实现jackson中会根据时区去转换时间,而jackson的默认时区跟国内是相差8小时的
需要在注解中添加timezone=“GMT+8”
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" ,timezone="GMT+8")
完美解决