This problem, a group of nausea. . Inability to Tucao
Original Address: https://blog.csdn.net/m0_38043362/article/details/78855196?utm_source=blogxgwz8
The cause of the problem, Internet search, it probably means: spring turn json default implementation jackson will go conversion time according to the time zone and the default time zone jackson is now the country is a difference of 8 hours, so there have to re-set the current project time zone where the ground.
3 ways I have tried, the first database configuration suitable for my project:
Region disposed serverTimezone = GMT + 8 additional database connection 1. application.yml application.properties file or, where the number is converted +% 2b using
spring: datasource: # 主数据源 datasource: driverClassName: com.mysql.jdbc.Driver jdbc-url: jdbc:mysql://localhost:3306/ga_qhfj_microffice?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2b8&useSSL=false username: root password: root
2. application.properties or application.yml add configuration
# application.properties profiling spring.jackson.time -zone GMT + = . 8 ---------------------------------- - # application.yml file to configure the Spring: jackson: Time -zone: GMT + 8
3. Return the entity class using annotations @JsonFormat
public class ArticleListVo { private Long articleId; @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") private Date createTime; }