SpringBoot解決前後端跨域問題WebMvcConfigurer
阿新 • • 發佈:2021-02-04
建立SessionConfiguration 類, 把程式碼copy裡就ok了
@Configuration
public class SessionConfiguration implements WebMvcConfigurer {
/***
* @Description: 解決跨域
* @Param: [registry]
*/
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping ("/**")
.allowedOrigins("*")
.allowCredentials(true)
.allowedMethods("GET", "POST", "DELETE", "PUT")
.maxAge(3600);
}
}