访问量: 34022次,访客数: 29090人,浏览量: 1次 
首页  编辑  

SpringBoot允许跨域请求CORS

Tags: /Java/   Date Created: Tue Jul 25 2023 05:07:15 GMT+0000 (Coordinated Universal Time)
 1 import org.springframework.web.servlet.config.annotation.CorsRegistry;
 2 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 3 
 4 public class WebMvcConfig implements WebMvcConfigurer {
 5     /**
 6      * 允许 CORS 请求,允许跨域请求
 7      *
 8      * @param registry
 9      */
10     @Override
11     public void addCorsMappings(CorsRegistry registry) {
12         registry.addMapping("/**").allowedMethods("GET", "POST");
13     }
14 }