java project file relationships scanning Comment injection (3) @RequestParam and @PathVariable usage summary

@RequestParam and @PathVariable usage summary

 https://www.cnblogs.com/helloworld-hyyx/p/5295514.html(copy)

@RequestParam

Receiving the preceding parameters using @RequestParam more convenient, the front end parameter passing URL:

url = “${ctx}/main/mm/am/edit?Id=${Id}&name=${name}”

Using a set of parameters to accept the rear end, better flexibility, url if no key value assigned to the parameter, when receiving the rear end, according to the type of the attached parameter values, assigned an initial key (String, long ......)

Copy the code
@RequestMapping("/edit")
    public String edit(Model model, @RequestParam Map<String, Object> paramMap ) {
        long id = Long.parseLong(paramMap.get("id").toString());
        String name = paramMap.get("name").toString;
        return page("edit");
    }
Copy the code

@PathVariable

Use @PathVariable reception parameter, the parameter values ​​required in the placeholder url, parameter passing distal URL:

url = “${ctx}/main/mm/am/edit/${Id}/${name}”

@RequestMapping("/edit/{id}/{name}")
    public String edit (Model model, @PathVariable long id, @ PathVariable String name) {
        
        return page("edit");
    }

The front end of the URL parameter passing to the back end of @RequestMapping URL parameters must be the same location and correspondence, will not find the back-end or front-end address

@RequestParam

Receiving the preceding parameters using @RequestParam more convenient, the front end parameter passing URL:

url = “${ctx}/main/mm/am/edit?Id=${Id}&name=${name}”

Using a set of parameters to accept the rear end, better flexibility, url if no key value assigned to the parameter, when receiving the rear end, according to the type of the attached parameter values, assigned an initial key (String, long ......)

Copy the code
@RequestMapping("/edit")
    public String edit(Model model, @RequestParam Map<String, Object> paramMap ) {
        long id = Long.parseLong(paramMap.get("id").toString());
        String name = paramMap.get("name").toString;
        return page("edit");
    }
Copy the code

@PathVariable

Use @PathVariable reception parameter, the parameter values ​​required in the placeholder url, parameter passing distal URL:

url = “${ctx}/main/mm/am/edit/${Id}/${name}”

@RequestMapping("/edit/{id}/{name}")
    public String edit (Model model, @PathVariable long id, @ PathVariable String name) {
        
        return page("edit");
    }

The front end of the URL parameter passing to the back end of @RequestMapping URL parameters must be the same location and correspondence, will not find the back-end or front-end address

Guess you like

Origin www.cnblogs.com/dianzan/p/11099862.html