@RestController对象中时间属性格式的统一处理方式
在项目中经常要对时间格式处理完成后统一返回前段页面,正常情况下java中Date属性直接转化为json显示的是时间戳
这里主要是针对springboot项目中处理时间方式
测试对象
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/3559e966032f2b2436dc45e3afc74e16.png)
结果输出对象ResultDate
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/fbc68a9aacf5f055c73f94bf70d1a1d0.png)
controller
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/ae8e9e78cd84d4d08aec1a438d7dfd83.png)
没添加时间处理
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/e3cf53b1e6bf30db592b6475895c767d.png)
需要用到的配置只要在application.properties中添加
#时间格式的统一处理
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
添加全局时间处理后
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/a1be8abd2f6d22fc0d71c4abb251c6e9.png)