zoukankan      html  css  js  c++  java
  • springboot2

    关键代码(在springboot1.5中不加这一块也是正常的,不知道为什么2.0就出现了这个问题)

        @Bean
        public HttpPutFormContentFilter httpPutFormContentFilter() {
            return new HttpPutFormContentFilter();
        }
    

     完整代码

    @Configuration
    @EnableWebMvc
    public class MyWebMvcConfigurer implements WebMvcConfigurer {
    
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            //设置允许跨域的路径
            registry.addMapping("/**")
                    //是否允许证书 不再默认开启
                    .allowCredentials(true)
                    .allowedOrigins("*")
                    .allowedMethods("*")
                    .allowedHeaders("*");
                    //跨域允许时间
    //                .maxAge(3600);
        }
    
        private CorsConfiguration addCorsConfig() {
            CorsConfiguration corsConfiguration = new CorsConfiguration();
            List<String> list = new ArrayList<>();
            list.add("*");
            corsConfiguration.setAllowedOrigins(list);
            //请求常用的三种配置,*代表允许所有,当时你也可以自定义属性(比如header只能带什么,只能是post方式等等)
            corsConfiguration.addAllowedOrigin("*");
            corsConfiguration.addAllowedHeader("*");
            corsConfiguration.addAllowedMethod("*");
            return corsConfiguration;
        }
    
        @Bean
        public CorsFilter corsFilter() {
            UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
            source.registerCorsConfiguration("/**", addCorsConfig());
            return new CorsFilter(source);
        }
    
        @Bean
        public HttpPutFormContentFilter httpPutFormContentFilter() {
            return new HttpPutFormContentFilter();
        }
    
    }
    
  • 相关阅读:
    python 类定义 继承
    BAYSY2 的LVDS引脚 笔记
    Fedora20-32bit cross-compiling arm-linux-gcc4.3.2
    以冒泡排序为例--malloc/free 重定向stdin stdout
    笔记:程序内存管理 .bss .data .rodata .text stack heap
    第一章 数值和码制
    《将博客搬至CSDN》
    Servlet 3.0 新特性
    java Servlet接口及应用
    C语言输出单个汉字字符
  • 原文地址:https://www.cnblogs.com/song-wentao/p/9354479.html
Copyright © 2011-2022 走看看