springboot后台解决跨域问题

直接上代码

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/*
* 解决跨域问题
* */
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {

public void addCorsMappings(CorsRegistry registry) {
System.out.println("--- 解决跨域问题 ---");
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("*")
.allowCredentials(true);//允许验证
}

}
原文地址:https://www.cnblogs.com/pengtaotao/p/14147958.html