KKSU
2024-11-21 80fd9e3da4b45285c29cdb380ce743202b0c2af4
src/main/java/cc/mrbird/febs/common/configure/WebMvcConfigure.java
@@ -2,6 +2,7 @@
import cc.mrbird.febs.common.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@@ -40,4 +41,14 @@
        registration.excludePathPatterns("/configuration/security");
        registration.excludePathPatterns("/swagger-resources");
    }
    @Override
    public void addCorsMappings( CorsRegistry registry) {
        // 跨域请求配置
        registry.addMapping("/**")//允许请求路径
                .allowedOrigins("*")//表示允许所有网址发起跨域请求
                .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")//表示允许跨域请求的方法
                .maxAge(3600)//表示在3600秒内不需要再发送预校验请求
                .allowCredentials(true);//允许客户端携带验证信息,即允许携带cookie
    }
}