package com.evo.common.config; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** * 类 * * @ClassName:WebConfig * @date: 2025年05月20日 13:24 * @author: andy.shi * @contact: 17330188597 * @remark: 开发人员联系方式 1042025947@qq.com/微信同步 */ // 在Spring Boot的配置类中添加CORS配置 @Configuration public class WebConfig implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") // 匹配所有接口 .allowedOrigins("localhost:8090") // 允许的前端域名 .allowedMethods("GET", "POST", "PUT", "DELETE") // 允许的HTTP方法 .allowedHeaders("*") // 允许的请求头 .allowCredentials(true); // 允许携带凭证(如Cookie) } }