@CrossOrigin
时间: 2023-10-01 07:08:40 浏览: 67
@CrossOrigin解决跨域问题
5星 · 资源好评率100%
@CrossOrigin is an annotation used in Spring Boot to enable Cross-Origin Resource Sharing (CORS) support. It allows HTTP requests from different origins to access resources on the server.
By default, browsers restrict cross-origin HTTP requests initiated from scripts, which can cause issues when developing web applications. The @CrossOrigin annotation allows developers to configure access control for their endpoints, specifying which origins (domains) are allowed to access the resources.
For example, to allow requests from all origins, you can use:
```
@CrossOrigin(origins = "*")
```
Or to restrict access to only specific origins:
```
@CrossOrigin(origins = {"http://localhost:8080", "https://example.com"})
```
The @CrossOrigin annotation can be added to individual methods or to the entire controller class.
阅读全文