Files
Hui-s-notebook/logseq-java/pages/跨域.md
2024-02-02 00:12:49 +08:00

18 lines
696 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
- 在每个接口上,使用`@CrossOrigin`
- 在SpringMVC的配置类上添加跨域配置
- ```java
- @Configuration
- public class SpringMvcConfigure implements WebMvcConfigurer {
- /**
- * 添加跨域相关配置
- * @param registry
- */
- @Override
- public void addCorsMappings(CorsRegistry registry) {
- registry.addMapping("/**")//所有的path路径请求都支持
- .allowedOrigins("*")
- .allowCredentials(true)//允许身份认证
- .allowedMethods("GET","POST","PUT","DELETE");//让所有的Rest架构风格的方法都支持跨域
- }
- }
```