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);
        }
    }
    

      

  • 相关阅读:
    函数组件在react懒加载的方式
    axios 封装
    react高阶组件+ref转发的组合使用
    Iterator & Iterable 和 Comparable&Comparator
    java.lang.Collections
    虚拟机类加载学习和思考
    垃圾收集器与内存分配策略
    jvm内存区域与内存溢出
    spring装配Bean过程
    索引知识点补充
  • 原文地址:https://www.cnblogs.com/matd/p/11188525.html
Copyright © 2011-2022 走看看