两者的作用都是将request里的参数的值绑定到contorller里的方法参数里的,区别在于,url不同
@PathVariable的url是这样的:http://host:port/.../path/参数值
@RequestMapping("/bookings/{booking}")
public String getBooking(@PathVariable Long booking) {
}
而@RequestParam的url是这样的:http://host:port/.../path?参数名=参数值
@RequestMapping(method = RequestMethod.GET)
public String setupForm(@RequestParam("petId") int petId, ModelMap model) {
Pet pet = this.clinic.loadPet(petId);
model.addAttribute("pet", pet);
return "petForm";
}