Print Friendly and PDF

Program:

package com.myapp;
import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

@Produces("application/xml")
@Path("customer")
public class CustomersResource {

  @GET
 public List<Customer> getCustomers(@QueryParam("name") String name) {
  return null;
 }

  @GET
 @Path("{id}")
 public Customer[] getCustomer(@DefaultValue("-1") @QueryParam("id") int id) {
  Customer cu=new Customer();
  cu.setAddress("Rohini");
  cu.setId(100);
  cu.setName("Naresh");
  
  Customer cus=new Customer();
  cus.setAddress("Sarai");
  cus.setId(101);
  cus.setName("Prateek");
     Customer cust[]= new Customer[2];
     cust[0]=cu;
     cust[1]=cus;
  return cust;
 }
 @POST
 @Path("add")
 @Produces("text/html")
 @Consumes("application/xml")
 public String addCustomer() 
{
  return "added";
 }
}
zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: