@RequestParam and @PathVariable usage summary
@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 ......)
@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"); }
@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 ......)
@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"); }
@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