What is the difference between @PathParam and @PathVariable

后端 未结 7 1599
天涯浪人
天涯浪人 2020-12-23 19:21

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

7条回答
  •  [愿得一人]
    2020-12-23 19:52

    @PathVariable

    @PathVariable it is the annotation, that is used in the URI for the incoming request.

    http://localhost:8080/restcalls/101?id=10&name=xyz

    @RequestParam

    @RequestParam annotation used for accessing the query parameter values from the request.

    public String getRestCalls(
    @RequestParam(value="id", required=true) int id,
    @RequestParam(value="name", required=true) String name){...}
    

    Note

    whatever we are requesting with rest call i.e, @PathVariable

    whatever we are accessing for writing queries i.e, @RequestParam

提交回复
热议问题