evo-Financial-pc/evo-admin/src/main/java/com/evo/common/config/WebConfig.java
2025-05-21 11:08:23 +08:00

29 lines
983 B
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}
}