This commit is contained in:
张松
2025-03-01 14:38:29 +08:00
parent f6dfc81e48
commit 73852f43d6

View File

@@ -1,23 +0,0 @@
package com.czg.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class MyWebConfig {
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOriginPatterns("*") // 允许所有前端访问
.allowedMethods("*") // 允许所有请求方法
.allowedHeaders("*") // 允许所有请求头
.allowCredentials(true); // 允许携带 Cookie
}
};
}
}