PathParam Annotation In Jersey

Jersey pathparam Annotation use to read data from url of rest webservice . @pathparam annotation  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. If you are new in restful web service ,  then i will recommended to you first read java jersey rest api example . In this example you will see restful web services example in java using eclipse step by step . First we discuss about what is PathParam value in below example .

Example of PaathParam value :

http://localhost:8080/JerseyDemo/rest/user/27

In this example , Where “27” is the id of the user . Using jersey annotation @PathParam we will get value 27 of id in our web service . Let’s see code for pathparam example in restful web services .

RESTful Web Services (JAX-RS) @PathParam Example

@Path("/user")
public class UserHander {

@GET
@Path("/{id}")
public Response addUser(@PathParam("id") int id) {
System.out.println("id=" + id);
String str = "id is=" + id;
return Response.status(Status.OK).entity(str).build();
}

}

We have discussed JAX-RS @PathParam tutorial in Jersey RESTful application . Now you have seen pathparam example and you can we  read also jersey queryparam example . If you are looking more jersey example , then should try jersey tutorial for beginners .

Leave a Reply

Your email address will not be published. Required fields are marked *

− 2 = 3