关于JSON
JSON是目前主流的前后端数据传输方式,Spring MVC中使用消息转换器HttpMessageConverter对JSON的转换提供了很好的支持,在Spring Boot中更进一步,对相关配置进行了简化,
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web<artifactId>
<dependency>
web的starter依赖中默认就加入了jackson-databind作为JSON处理器,此时不要添加额外的JSON处理器就能返回一段JSON。
问题
默认情况下json时间格式带有时区,并且是世界标准时间,和我们的时间差了八个小时
解决
在application.properties中添加设置
#返回json的全局时间格式
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8