@PathVariable和@RequestParam区别
@RestController
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;
@GetMapping("/{id}")
public User findById(@PathVariable Long id){
return userService.findById(id);
}
@GetMapping("/id")
public User findById1(@RequestParam("id") Long id){
return userService.findById(id);
}
http: //localhost:9090/user/8
@PathVariable 访问user/{id} 这个id会被替换8替换
http://localhost:9090/user/id?id=8
@RequestParam 获取的是 ‘’?" 后面参数的值