页面网址:
http://127.0.0.1:8848/xxx/xxxx.html
里面有个js,ajax请求后台地址为:
http://localhost:8080/user/list
直接报错:
前端看到返回的报错:Invalid CORS request
只需要在springboot后台加上下面的代码:
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOriginPatterns("*")
.allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
.maxAge(3600)
.allowCredentials(true);
}
}
搞定