Description: this article is talking about the difference between @RequestParam and @PathVariable
@RequestParam
mainly used for the controller to solve the issue of different variable names between the front end and back end, this annotation equals to request.getParam.
1 | // value: paramter name. |
- localhost:8080/demo1?name=Aaron&age=18
@PathVariable
it mainly used for receiving http://host:port/path/{parameter}data
when the request URL is localhost:8080/demo2/Bob/12, The parameters of the URL placeholder will be bound to the corresponding parameters of the demo2 method by name
1 |
|
@RequestBody
in post request, when the URL is /user/UpdateAddressByUaId
1 |
|
Reference
- [1] @RequestParam