有下面两段代码:
@RequestMapping("getUser/{id}")
public String GetUser(@PathVariable int id) {
return userService.findById(id).toString();
}
@RequestMapping(path = "/del")
public String del(@RequestParam(name = "user_id") Integer user_id) {
userService.delById(user_id);
return "redirect:/userlist";
}
@PathVariable是请求路径,是从路径中获取变量,也就是把路径当做变量。
@RequestParam是请求参数,就是获取参数的。
如下面两个例子:
地址1:http://localhost:8989/SSSP/emps?pageNo=3
地址2:http://localhost:8989/SSSP/emp/8
如果想获取地址1中的 pageNo的值 ‘3’ ,则使用 @RequestParam ,
如果想获取地址2中的 emp/8 中的 ‘8’ 则使用 @PathVariable
本文暂时没有评论,来添加一个吧(●'◡'●)