普通设置
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Headers", "*");
response.setHeader("Access-Control-Allow-Methods", "*");
SpringBoot 中实现 WebMvcConfigurer
接口,并重写 addCorsMappings
方法
@Override
public void addCorsMappings(CorsRegistry registry) {
registry
.addMapping("/**")
.allowedOrigins("*")
.allowedHeaders("*")
.allowedMethods("*")
.allowCredentials(false)
.maxAge(3600);
}
原文地址:https://www.cnblogs.com/StarUDream/p/9045541.html
时间: 2024-10-30 06:15:49