@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;
    }

 

相关文章:

  • 2021-05-03
  • 2021-05-23
  • 2021-05-27
  • 2021-07-20
  • 2021-11-25
  • 2021-10-21
  • 2022-02-05
猜你喜欢
  • 2021-08-11
  • 2021-09-24
  • 2021-07-07
  • 2021-06-25
  • 2021-07-27
  • 2022-02-02
  • 2021-11-20
相关资源
相似解决方案