zoukankan      html  css  js  c++  java
  • WebMvcConfigurationSupport跨域和fastjson全局替换

    @Configuration
    public class WarnWebMvcConfigurationSupport extends WebMvcConfigurationSupport {
    
        /**
         * @Author AlanMa
         * @Description 全局fastJson替换
         * @Param [converters]
         * @return void
         */
        @Override
        public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
            super.configureMessageConverters(converters);
    
            FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
    
            FastJsonConfig fastJsonConfig = new FastJsonConfig();
            fastJsonConfig.setSerializerFeatures(
                    SerializerFeature.PrettyFormat,
                    SerializerFeature.WriteNullListAsEmpty,
                    SerializerFeature.WriteMapNullValue,
                    SerializerFeature.WriteEnumUsingToString,
                    SerializerFeature.WriteNullStringAsEmpty);
    
            fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
            List<MediaType> fastMediaTypes = new ArrayList<>();
            fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
            fastConverter.setSupportedMediaTypes(fastMediaTypes);
            fastConverter.setFastJsonConfig(fastJsonConfig);
            converters.add(fastConverter);
        }
    
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**")
                    .allowedOrigins("*")
                    .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
                    .maxAge(3600)
                    .allowCredentials(true);
        }
    }
    

      

  • 相关阅读:
    DB开发之oracle存储过程
    DB开发之mysql
    DB开发之oracle
    DB开发之postgresql
    Object-C开发之instancetype和id关键字
    Linux 学习笔记
    Java开发之JDK配置
    Android开发在路上:少去踩坑,多走捷径
    C/C++之Qt正则表达式
    Linux 安全配置指南
  • 原文地址:https://www.cnblogs.com/matd/p/11188525.html
Copyright © 2011-2022 走看看