Difference between JAX-RS @PathParam and @QueryParam




Asked on March 10, 2015
What is difference between JAX-RS @PathParam and @QueryParam?


Replied on April 17, 2015
PathParam and @QueryParam both are the JAX-RS API.

PathParam can be used as 

/test/data/{id}/{name}

/test/123/Ram

@Path("/data/{id}/{name}")
        @Produces("text/plain")
public String add(@PathParam("id") Integer id, @PathParam("name") String name ){
          //ToDo
         return "result";
}

For more detail, find the URL



QueryParam can be used as 

/test/data?id=123&name=Ram

       @Path("/data/{id}/{name}")
        @Produces("text/plain")
public String add(@QueryParam("id") Integer id, @QueryParam("name") String name ){
          //ToDo
         return "result";
}

For more detail, find the URL.







Replied on October 14, 2016

DIFFERENCE BETWEEN PathParam and QueryParam: 

Query parameters are added to the url after the ? mark, while a path parameter is part of the regular URL.

In the URL below tom could be the value of a path parameter and there is one query parameter with the name id and value .



Write Answer











©2024 concretepage.com | Privacy Policy | Contact Us