SpringBoot 拦截器WebMvcConfigurationSupport导致date-format时间格式失效


1、继承WebMvcConfigurationSupport实现自定义拦截器后,原先配置的时间格式返回变成时间戳,以下配置失效:

spring
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss
    time-zone: GMT+8

2、解决办法不继承WebMvcConfigurationSupport,修改为实现WebMvcConfigurer接口

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Resource
    private JwtInterceptor jwtInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(jwtInterceptor)
                //拦截所有url
                .addPathPatterns("/**")
                //排除登录url
                .excludePathPatterns("/", "/login");

    }
}

3、另外还有方式就是引入fastjson替换jackson。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM