Java controller parameter annotation

Java controller parameter annotation

  1. @PathVariavle
    pathvariable is to store the variable in the url, which is more suitable for the case where there are few transmission variables. But it can also be used to transfer multiple variables. such as:

    Front desk: targetUrl/parameter1/parameter2/parameter
    3Background @RequestMapping("targetUrl/{parameter 1}/{parameter 2}/{parameter 3}")
    public void getHeader(@Pathvariable parameter 1, @PathVariable parameter 2)
    Note : There can be no "/" in the parameters. If there is "/", the parameters will not be obtained in the background. If there is "/", you can use @ instead, and then translate it into "/" in the background

  2. @RequestParam json objects can be used to transmit, value is the name of the field corresponding to
    , for example: @RequestParam (value = "name" , required = "false").
    @RequestParam and @PathVariable two annotations can be used at the same time

3 Directly use the object to receive the json string from the front desk
@PostMapping
public void saveHeader (Header header){}

Guess you like

Origin blog.csdn.net/weixin_38813363/article/details/81215130