java跨域配置

x33g5p2x  于2022-05-28 转载在 Java  
字(0.6k)|赞(0)|评价(0)|浏览(188)

java跨域:

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

@Configuration
public class MyWebConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
                //.allowCredentials(true)
                .allowedHeaders("*")
                .maxAge(3600);
    }
}

相关文章

微信公众号

最新文章

更多