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 
版權聲明:本文爲博主原創文章,轉載請附上博文鏈接!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章