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

时间:2020-04-22 16:49:00   收藏:0   阅读:427

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。

 

原文:https://www.cnblogs.com/asker009/p/12752716.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!