feat(新增): 解决跨域

This commit is contained in:
bunny 2024-03-22 21:19:38 +08:00
parent 919e428e9e
commit 77cbffcd06
1 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,22 @@
package com.atguigu.config;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Component
public class WebMvcConfiguration implements WebMvcConfigurer {
/**
* * 解决跨域
*
* @param registry 跨域注册表
*/
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")// 添加路径规则
.allowCredentials(true)// 是否允许在跨域的情况下传递Cookie
.allowedOriginPatterns("*")// 允许请求来源的域规则
.allowedMethods("*")
.allowedHeaders("*");// 允许所有的请求头
}
}