CORS跨域分为后端和前端两个步骤
后端解决
实现WebMvcConfigur
@Configuration public class WebConfig implements WebMvcConfigurer { }
重写addCorsMappings
@Configuration public class WebConfig implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") .allowCredentials(true) .allowedOrigins("*") .allowedMethods(new String[]{"GET","PUT","POST","DELETE"}) .allowedHeaders("*") .exposedHeaders("*") .maxAge(3600); } }
前端解决
临时解决 (写法麻烦)
$.ajax({ type: "get", async: true, url: "http://localhost/sign", xhrFields: {

本文详细介绍了如何使用SpringBoot在后端配置CORS跨域,并提供了前端的临时和永久解决方法。此外,还分享了SpringBoot设置Cookie的相关知识,包括MaxAge的设置以及Secure和HttpOnly属性的用法。
最低0.47元/天 解锁文章
611

被折叠的 条评论
为什么被折叠?



