项目类型:springboot+mybatis-plus
配置跨域请求时allowedOrigins与allowedOriginPatterns的问题
//后端配置的地址跨域请求
@Configuration
public class CrosConfig {
@Bean
public WebMvcConfigurer webMvcConfigurer() {
return new WebMvcConfigurer() {
//配置跨域
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**") //允许的路径
.allowedMethods("*") //允许的方法
.allowedOriginPatterns("*") //允许的网站
.allowedHeaders("*") //允许的请求头
.allowCredentials(true)
.maxAge(3600);
}
};
}
}
本文详细解读了在SpringBoot项目中使用Mybatis-Plus进行后端配置时,如何正确设置CORS允许的源(allowedOrigins)和允许的源模式(allowedOriginPatterns),帮助开发者解决跨域问题。
4076

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



