Respect for the original: 790,716,831, problem description
Because the project is a front-end separation, the backend uses spring boot, which is made into microservices, exposing only the interface. Interface design style for the restful style, in the GET request, the background receive parameter annotation is requestbody error, in the POST request, the background receives the parameter annotation is Requestparam will also error.
Second, the cause of the problem
Since spring's requestparam annotations receive parameters from Requestheader, which is the request header, which is in the URL, the format is xxx?username=123&password= 456, while the requestbody annotation receives the parameter from the Requestbody, which is the request body.
Third, the solution
Therefore, in summary, if a GET request, the background receive parameter annotation should be requestparam, if it is a POST request, the background receive parameter annotation is requestbody. Attached are two examples, as follows:
GET request
POST request
In addition, there is an application scenario, the interface specification for the resultful style, for example: If you want to get an ID under the question of the answer to the number of queries, then the background needs to dynamically get the parameters, the annotation is @pathvariable, and the value in requestmapping should be value= "/{id}/querynum", as follows:
The difference between spring Boot's @requestparam and @requestbody