import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
@Path("/employees")
public class EmployeeRestService {
@GET
@Path("{employeeId}")
public Response getEmployeeById(@PathParam("employeeId") String employeeId) {
return Response.status(200).entity("getEmployeeById is called, employeeId : " + employeeId).build();
}
}
In above example, the value of {employeeId} from "/employees/{employeeId}" will match to "@PathParam("employeeId") String var".import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
@Path("/employees")
public class EmployeeRestService {
@GET
@Path("{year}/{month}/{day}")
public Response getEmployeeHistory(
@PathParam("year") int year,
@PathParam("month") int month,
@PathParam("day") int day) {
String date = year + "/" + month + "/" + day;
return Response.status(200)
.entity("getEmployeeHistory is called, year/month/day : " + date)
.build();
}
}
URI Pattern : "/employees/2013/06/16"Labels: REST