@GetMapping(value = "/hello/{id}")//需要获取Url=localhost:8080/hello/id中的id值 public String sayHello(@PathVariable("id") Integer id){ return "id:"+id; } @GetMapping(value="/hello/{id}/{name}")//需要在url有多个参数需要获取 public String sayHello(@PathVariable("id") Integer id,@PathVariable("name") String name){ return "id:"+id+" name:"+name; } @GetMapping(value="/hello")//localhost:8080/hello?id=98,@RequestParam 获取请求参数的值 public String hello(@RequestParam("id") Integer id,@RequestParam("access_token")String accessToken){ return "id:"+id+" accessToken:"+accessToken; } @GetMapping(value="/hello1")//我们在浏览器中输入地址:localhost:8080/hello ,即不输入id参数,则报错 Required Integer parameter 'id' is not present //可以添加默认参数 public String hello1(@RequestParam(value = "id",required = false,defaultValue = "1") Integer id,@RequestParam("access_token")String accessToken){ return "id:"+id+" accessToken:"+accessToken; }