@Test public void testUpdateEmployee(){ Department department = new Department(1,"研发部"); Employee employee = new Employee(1,"scott",department); JAXBElement<Employee> element = new JAXBElement<Employee>(new QName("employee"), Employee.class, employee); Response response = target("employee").request().put(Entity.entity(element,MediaType.APPLICATION_XML)); System.out.println(response.getStatus()); System.out.println(response.readEntity(String.class)); }
@PUT public JAXBElement<Employee> updateEmployee(JAXBElement<Employee> employee){ Employee value = employee.getValue(); value.setEname("乔布斯"); value.getDepartment().setDeptname("apple"); return new JAXBElement<Employee>(new QName("employee"), Employee.class, value); }
EmployeeRestService { @PUT public JAXBElement<Employee> updateEmployee(JAXBElement<Employee> employee){ Employee value = employee.getValue(); value.setEname("乔布斯"); value.getDepartment().setDeptname("apple"); return new JAXBElement<Employee>(new QName("employee"), Employee.class, value); } }
EmployeeRestService { @PUT public JAXBElement<Employee> updateEmployee(JAXBElement<Employee> employee){ Employee value = employee.getValue(); value.setEname("乔布斯"); value.getDepartment().setDeptname("apple"); return new JAXBElement<Employee>(new QName("employee"), Employee.class, value); }  }
EmployeeRestService { @PUT public JAXBElement<Employee> updateEmployee(JAXBElement<Employee> employee){ Employee value = employee.getValue(); value.setEname("乔布斯"); value.getDepartment().setDeptname("apple"); return new JAXBElement<Employee>(new QName("employee"), Employee.class, value); }  @Path("/v1") @GET List<JAXBElement<Employee>> getEmployees(); @Path("{id}") @GET JAXBElement<Employee> getEmployee(@PathParam("id")int id); @POST JAXBElement<Employee> saveEmployee(JAXBElement<Employee> employee); @PUT JAXBElement<Employee> updateEmployee(JAXBElement<Employee> employee); @DELETE @Path("{id}") JAXBElement<Employee> deleteEmployee(@PathParam("id")int id); }
EmployeeRestService { @PUT public JAXBElement<Employee> updateEmployee(JAXBElement<Employee> employee){ Employee value = employee.getValue(); value.setEname("乔布斯"); value.getDepartment().setDeptname("apple"); return new JAXBElement<Employee>(new QName("employee"), Employee.class, value); }  @Path("/v1") @GET List<JAXBElement<Employee>> getEmployees(); @Path("{id}") @GET JAXBElement<Employee> getEmployee(@PathParam("id")int id); @POST JAXBElement<Employee> saveEmployee(JAXBElement<Employee> employee); @PUT JAXBElement<Employee> updateEmployee(JAXBElement<Employee> employee); @DELETE @Path("{id}") JAXBElement<Employee> deleteEmployee(@PathParam("id")int id);  }