0

My understanding is request parameters is the required id for the method to pass while path variable says this variable should be found in the request process

   @PreAuthorize("hasRole('ROLE_COACH')")

    @PostMapping(value = "/courses/{courseId}/background/update")

    @ResponseStatus(HttpStatus.ACCEPTED)

    @ResponseBody

    public CourseLiteInfo updateBackground(@RequestParam("file") MultipartFile file,

                                           @PathVariable(value = "courseId") Long courseId) throws IOException {



        return new CourseLiteInfo(courseService.updateBackground(courseId, file));
}
valik
  • 2,014
  • 4
  • 24
  • 55

3 Answers3

3

Hi,

@RequestParam is a parameter binded as a query param. This parameter can be optional to apply a filter, for example.

google.com?query=param

@PathVariable is a parameter binded as a param in the url. This parameter is required to be informed.

yourapp.com/users/pathparam
0

RequestParam maps to a named URL parameter on the URL.

PathVariable is a part of the URL path that can be changed but still maps to the same controller mapping

For e.g.

http://somedomain.com/account/123/details?type=sometype

Here 123 would be a PathVariable that can be named anything we want and sometype is the value of a RequestParam which has to be name type.

zatopek
  • 333
  • 2
  • 8
0

@QueryParam is used to access key/value pairs in the query string of the URL (the part after the ?). For example in the url http://stackoverflow.com/questions?q=query, you can use @QueryParam("q") to get the value of q.

@PathParam is used to match a part of the URL as a parameter. For example in an url of the form http://stackoverflow.com/questions/{questionid}, you can use @PathParam("questionid") to get the id of a question