目录结构:
只需要编写一个类,实现WebMvcConfigurer接口中的addCorsMappings方法即可:
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;/*** 前端请求后端的数据,因为前端端口后是8080,后端端口后是8181* 这个类的功能是是解决跨域问题(跨域问题可以在前端解决亦可以在后端解决),这就是在后端解决*/
@Configuration
public class CrosConfig implements WebMvcConfigurer { //implements WebMvcConfigurer重写下面的方法@Overridepublic void addCorsMappings(CorsRegistry registry) {registry.addMapping("/**").allowedOrigins("*").allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS").allowCredentials(true).maxAge(3600).allowedHeaders("*");}
}
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态