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。

猜你喜欢

转载自www.cnblogs.com/asker009/p/12752716.html
今日推荐