Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between @PathParam and @PathVariable [closed]

To my knowledge both serves the same purpose. Except the fact that @PathVariable is from Spring MVC and @PathParam is from JAX-RS. Any insights on this?

like image 251
suresh Avatar asked Sep 03 '15 05:09

suresh


People also ask

What is the difference between @PathParam and @QueryParam?

@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://example.com?q=searchterm , you can use @QueryParam("q") to get the value of q . @PathParam is used to match a part of the URL as a parameter.

What is the difference between @RequestParam and @PathVariable annotation?

Difference between @PathVariable and @RequestParam in Spring 1) The @RequestParam is used to extract query parameters while @PathVariable is used to extract data right from the URI.

What's the main difference between @PathVariable and RequestParam?

The key difference between @RequestParam and @PathVariable is that @RequestParam used for accessing the values of the query parameters where as @PathVariable used for accessing the values from the URI template.

What does @PathVariable annotation do?

The @PathVariable annotation is used to extract the value of the template variables and assign their value to a method variable.


1 Answers

@PathVariable and @PathParam both are used for accessing parameters from URI Template

Differences:

  • As you mention @PathVariable is from spring and @PathParam is from JAX-RS.
  • @PathParam can use with REST only, where @PathVariable used in Spring so it works in MVC and REST.
like image 200
Premraj Avatar answered Oct 16 '22 12:10

Premraj