前后端分离需要配置

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 CrosConfig implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
    // 设置允许跨域的路由
    registry.addMapping("/**")
            // 设置允许跨域请求的域名------------修改此行
            .allowedOriginPatterns("*")
            .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
            // 是否允许证书(cookies)
            .allowCredentials(true)
            // 设置允许的方法
            .allowedMethods("*")
            // 跨域允许时间
            .maxAge(3600);
}
}

 

posted @ 2022-09-23 14:08  熬夜遭毒打  阅读(44)  评论(0)    收藏  举报