And the difference between the use of @RequestParam and @PathVariable

Difference on the request path: Obviously one is? Key-value pairs, one is / parameter, the difference is obvious

@RequestParam used to obtain parameters available? Username = "sss" this? The parameter value of

Such as: access path is: http: // localhost: 7012 / billing / pay / paySerial paySerialId = 20190821155435120115620216832?

    @GetMapping("/paySerial")
//    @RequestMapping(value= "/paySerial",method =RequestMethod.GET)
    public PaySerialRes qryPaySerialDetail(@RequestParam(name = "paySerialId", required = false) String paySerialId) {
        log.info("传入的id为;{}",paySerialId);
        return paySerialService.qryPaySerialDetail(paySerialId);

When the method name and parameters passed in the name of the same, can be directly @RequestParam String paySerialId, as requested url: http: // localhost: 7012 / billing / pay / paySerial paySerialId = 20190821155435120115620216832?

On @RequestParam (name = "abc" String paySerialId, abc this way can be mapped and paySerialId: If the requested parameter is inconsistent and method names: the

abc and parameter names brought over the same request, such as: http: // localhost: 7012 / billing / pay / paySerial abc = 20190821155435120115620216832;?

@RequestParam(value = "paySerialId", required = false, defaultValue = "1")

@RequestParam supports the following four parameters

defaultValue if this request does not carry this argument, or parameter is empty, it will enable the default value
name name of this binding parameters, keep the same URL above
required parameters must be passed if the default is true, meaning the request the corresponding parameters must be, otherwise it will report a 404 error code;
value with the same name of the role, is an alias name attribute

 

 

 

Use @PathVariable reception parameter, the parameter values ​​need to be occupying in url, the front end parameter passing URL: url = "/ main / mm / am / $ {Id} / $ {name}"

如:http://localhost:7012/billing/pay/paySerial/20190821155435120115620216832

    @GetMapping("/paySerial/{aaaa}")
    public PaySerialRes qryPaySerialDetail(@PathVariable("aaaa") String paySerialId) {
        log.info("传入的id为;{}",paySerialId);
        return paySerialService.qryPaySerialDetail(paySerialId);
    }

 

Guess you like

Origin www.cnblogs.com/cherishforchen/p/11402760.html