Search code examples
spring-mvcjax-rsrestful-urlpath-parameter

What is the difference between @PathParam and @PathVariable


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


Solution

  • @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.

    See also: Difference between @RequestParam and @QueryParam Anotation