Since the development of the front-end, there have been many proxy tools that can help us solve cross-domain problems.
But in the final analysis, it is best if the back-end can solve cross-domain problems.
So let's look at a request first.
It's obvious that this interface is cross-domain
because I'm using Spring MVC here
, and Spring MVC is very simple to solve cross-domain code.
We only need to add an annotation
@CrossOrigin.
The reference code is as follows
@CrossOrigin(origins = "*", allowedHeaders = "*")
First, CrossOrigin has two parameters. The first origins represents the allowed sources. Give an asterisk to represent all sources. The
second parameter allowedHeaders specifies an asterisk to indicate that there is no restriction
on placing it on the class name. In this way, we are equivalent to letting go of all sources. limit
Then we start the project again
and then access the front-end service.
You can see that the front-end successfully requested the data back this time.