1. 程式人生 > >springboot 2.0 配置 spring.jackson.date-format 不生效

springboot 2.0 配置 spring.jackson.date-format 不生效

問題:application.properties中的如下配置不生效,返回時間戳

spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
原因分析:

       攔截器繼承的 WebMvcConfigurationSupport !

       以前是用 WebMvcConfigurerAdapter ,springboot 2.0 建議使用 WebMvcConfigurationSupport 。但是在新增攔截器並繼承 WebMvcConfigurationSupport 後會覆蓋@EnableAutoConfiguration關於WebMvcAutoConfiguration的配置!從而導致所有的Date返回都變成時間戳!

解決方法:

       實現 WebMvcConfigurer。

       將:

extends WebMvcConfigurationSupport
       改為:

implements WebMvcConfigurer
引用:

SpringBoot攔截器WebMvcConfigurationSupport導致date-format失效

@EnableWebMvc,WebMvcConfigurationSupport,WebMvcConfigurer和WebMvcConfigurationAdapter區別
--------------------- 
作者:2yung 
來源:CSDN 
原文:https://blog.csdn.net/qq_30912043/article/details/80967352 
版權宣告:本文為博主原創文章,轉載請附上博文連結!