Access to fetch at 'http://localhost:8085/user/selectPage' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
SpringBoot解决跨域问题,粘上如下代码即可
//解决跨域访问的配置 @Configuration public class CorsConfig implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry) { //path:“/**”表示的是拦截对应域名下的所有请求,也可以自行设置请求路径。 registry.addMapping("/**") //allowedOrigins:设置能跨域访问我的域名,其中*号代表任意域名。 .allowedOriginPatterns("*") //allowCredentials:是否允许携带cookie?默认情况下值为false。 .allowCredentials(true) //allowMethod:接受的请求方式。 .allowedMethods("GET","POST","PUT","DELETE") //maxAge:本次许可的有效时长,单位是秒 .maxAge(3600); } }