in Spring by
What are the differences between @RequestParam and @PathVariable annotations?

► Click here to show 1 Answer

0 votes

Even though both these annotations are used to extract some data from URL, there is a key difference between them.

The @RequestParam is used to extract query parameters that is anything after "?" in the URL.

The @PathVariable is used to extract the data present as part of the URI itself.

Example, if the given URL is http://localhost:8080/InterviewBit/Spring/SpringMVC/?format=json, then you can access the query parameter "format" using the @RequestParam annotation and /Spring/{type} using the @PathVariable, which will give you SpringMVC.


  public void getQuestions(@PathVariable("type") String type, 

                           @RequestParam(value = "format", required = false) String format){

      /* Some code */


Learn More with Madanswer

Related questions

0 votes
asked Apr 4 in Spring by Robindeniel