This commit is contained in:
张松 2025-03-01 14:34:51 +08:00
parent d925081861
commit f6dfc81e48
1 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,23 @@
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
}
};
}
}