@RequestParam与@PathVariable的区别
@RequestMapping(value="/user",method = RequestMethod.GET) public @ResponseBody User printUser(@RequestParam(value = "id", required = false, defaultValue = "0") int id) { User user = new User(); user = userService.getUserById(id); return user; } @RequestMapping(value="/user/{id:\\d+}",method = RequestMethod.GET) public @ResponseBody User printUser2(@PathVariable int id) { User user = new User(); user = userService.getUserById(id); return user; }