What is the difference between @PathParam and @QueryParam

I am newbie in RESTful jersey. I would like to ask what is the different between @PathParam and @QueryParam in jersey?


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 1:

http://mydomain.com/tom?id=1


Along with the above clarification provided by @Ruben, I want to add that you can also refer equivalent of the same in Spring RESTFull implementation.

JAX- RS Specification @PathParam - Binds the value of a URI template parameter or a path segment containing the template parameter to a resource method parameter, resource class field, or resource class bean property.

@Path("/users/{username}")
public class UserResource {

        @GET
        @Produces("text/xml")
        public String getUser(@PathParam("username") String userName) {
            ...
        }
    }

@QueryParam - Binds the value(s) of a HTTP query parameter to a resource method parameter, resource class field, or resource class bean property.

URI : users/query?from=100

@Path("/users")
public class UserService {

    @GET
    @Path("/query")
    public Response getUsers(
        @QueryParam("from") int from){
}}

To achieve the same using Spring, you can use

@PathVariable(Spring) == @PathParam(Jersey, JAX-RS),

@RequestParam(Spring) == @QueryParam(Jersey, JAX-RS)