How do I retrieve query parameters in Spring Boot?

前端 未结 5 956
慢半拍i
慢半拍i 2020-12-12 14:23

I am developing a project using Spring Boot. I\'ve a controller which accepts GET requests.

Currently I\'m accepting requests to the following kind of URLs:

5条回答
  •  再見小時候
    2020-12-12 15:23

    I was interested in this as well and came across some examples on the Spring Boot site.

       // get with query string parameters e.g. /system/resource?id="rtze1cd2"&person="sam smith" 
    // so below the first query parameter id is the variable and name is the variable
    // id is shown below as a RequestParam
        @GetMapping("/system/resource")
        // this is for swagger docs
        @ApiOperation(value = "Get the resource identified by id and person")
        ResponseEntity getSomeResourceWithParameters(@RequestParam String id, @RequestParam("person") String name) {
    
            InterestingResource resource = getMyInterestingResourc(id, name);
            logger.info("Request to get an id of "+id+" with a name of person: "+name);
    
            return new ResponseEntity(resource, HttpStatus.OK);
        }
    
    
    

    See here also

    提交回复
    热议问题