application.properties
# JACKSON (JacksonProperties)
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
第一个设置就是使用24小时的时间格式;第二个设置就是设置时区为东八区。
bean
@JsonFormat
private Date modifyDate;
然后,在你想要格式化的属性上面使用@JsonFormat
注解。
后续
如果使用了extends WebMvcConfigurationSupport
方式配置,如果想要使用上面的方式配置时间格式,需要将extends WebMvcConfigurationSupport
替换为implements WebMvcConfigurer
。
参考
Appendix A. Common application properties
Custom WebMvcConfiguration breaks Jackson formatting