Jersey @PathParam webservices Restful JAX-RS tutorial


@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. 


            If a class and a sub-resource method are both annotated with a @Path containing the same URI template parameter, use of @PathParam on a sub-resource method parameter will bind the value matching URI template parameter in the method's @Path annotation.


            Because injection occurs at object creation time, use of this annotation on resource class fields and bean properties is only supported for the default per-request resource class lifecycle. Resource classes using other lifecycles should only use this annotation on resource method parameters.


Code

package com.candidjava.webservices.controller;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.candidjava.webservices.bean.User;

@Path("/User")
public class RegisterProcess {

	@GET
	@Path("/welcomeMap/{countryName}/{userName}")
	@Produces(MediaType.APPLICATION_JSON)
	public Response getRegisterDetails2(
			@PathParam("countryName") String countryname,
			@PathParam("userName") String username) {

		System.out.println(countryname);
		System.out.println(username);

		User user = new User(countryname, username);

		return Response.ok().status(200).entity(user).build();

	}

}


Screenshot

            

            

Download

            Jersey @PathParam maven zip

            Jersey @PathParam war





Related Post

Comments


©candidjava.com