What is the difference between @PathParam and @QueryParam

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)


Additionally, query parameter can be null but path parameter can't. If you don't append the path parameter, you will get 404 error. So you can use path parameter if you want to send the data as mandatory.


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.example/tom?id=1