@PathVariable:
要在@GetMapping后面加上/{属性名}
(会按顺序匹配属性值,如(@PathVariable int userId,@PathVariable String userName),则为(/show/1/xiaoming),匹配userId为1,userName为xiaoming的)
@GetMapping("/show/{userId}")
public UserRepresentation show(@PathVariable int userId){
return userService.findById(userId);
}
@RequestMapping
要在访问路径上加上/属性名=属性值
@GetMapping("/show")
public UserRepresentation show(@RequestParam(value = "userId") int userId){
return userService.findById(userId);
}