@Test public void testGetStudentsV2(){ Response response = target("/student").path("v2").request().accept(MediaType.APPLICATION_XML).get(); System.out.println(response.getStatus()); System.out.println(response.readEntity(String.class)); System.out.println("-----------------------------------------------------"); response = target("/student").path("v2").request().accept(MediaType.APPLICATION_JSON).get(); System.out.println(response.getStatus()); System.out.println(response.readEntity(String.class)); }
@Path("/v2") @GET public List<Student> getStudentsV2() { List<Student> students = new ArrayList<Student>(); ClassRoom classRoom = new ClassRoom(); classRoom.setCid(1); classRoom.setClassname("三年二班"); for (int i = 1; i <= 100; i++) { Student student = new Student(i,"SCOTT"); student.setClassRoom(classRoom); students.add(student); } return students; }
StudentRestService { @Path("/v2") @GET public List<Student> getStudentsV2() { List<Student> students = new ArrayList<Student>(); ClassRoom classRoom = new ClassRoom(); classRoom.setCid(1); classRoom.setClassname("三年二班"); for (int i = 1; i <= 100; i++) { Student student = new Student(i,"SCOTT"); student.setClassRoom(classRoom); students.add(student); } return students; } }
StudentRestService { @Path("/v2") @GET public List<Student> getStudentsV2() { List<Student> students = new ArrayList<Student>(); ClassRoom classRoom = new ClassRoom(); classRoom.setCid(1); classRoom.setClassname("三年二班"); for (int i = 1; i <= 100; i++) { Student student = new Student(i,"SCOTT"); student.setClassRoom(classRoom); students.add(student); } return students; }  }
StudentRestService { @Path("/v2") @GET public List<Student> getStudentsV2() { List<Student> students = new ArrayList<Student>(); ClassRoom classRoom = new ClassRoom(); classRoom.setCid(1); classRoom.setClassname("三年二班"); for (int i = 1; i <= 100; i++) { Student student = new Student(i,"SCOTT"); student.setClassRoom(classRoom); students.add(student); } return students; }  @Path("/v1") @GET Response getStudentsV1(); @Path("/v2") @GET List<Student> getStudentsV2(); @Path("/v3") @GET Students getStudentsV3(); @Path("/v4") @GET Students getStudentsV4(@QueryParam("pageNumber")int pageNumber,@DefaultValue("20")@QueryParam("pageSize")int pageSize); @Path("/v5") @JSONP(callback="jsonp",queryParam="callback") @Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON,"application/javascript"}) @GET Students getStudentsV5(@QueryParam("pageNumber")int pageNumber,@DefaultValue("20")@QueryParam("pageSize")int pageSize); @GET @Path("/json/{id}") @Produces(MediaType.APPLICATION_JSON) Response getStudentInJson(@PathParam("id") int id); @GET @Path("/jsonp/{id}") @JSONP(callback="jsonp",queryParam="callback") @Produces("application/javascript") Response getStudentInJsonp(@PathParam("id") int id); @GET @Path("/xml/{id}") @Produces(MediaType.APPLICATION_XML) Response getStudentInXml(@PathParam("id") int id); @GET @Path("/{id}") Response getStudentInfo(@PathParam("id") int id); @DELETE @Path("/{id}") Response removeStudent(@PathParam("id") int id); @POST Response saveStudent(Student student); @PUT Response updateStudent(Student student); }
StudentRestService { @Path("/v2") @GET public List<Student> getStudentsV2() { List<Student> students = new ArrayList<Student>(); ClassRoom classRoom = new ClassRoom(); classRoom.setCid(1); classRoom.setClassname("三年二班"); for (int i = 1; i <= 100; i++) { Student student = new Student(i,"SCOTT"); student.setClassRoom(classRoom); students.add(student); } return students; }  @Path("/v1") @GET Response getStudentsV1(); @Path("/v2") @GET List<Student> getStudentsV2(); @Path("/v3") @GET Students getStudentsV3(); @Path("/v4") @GET Students getStudentsV4(@QueryParam("pageNumber")int pageNumber,@DefaultValue("20")@QueryParam("pageSize")int pageSize); @Path("/v5") @JSONP(callback="jsonp",queryParam="callback") @Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON,"application/javascript"}) @GET Students getStudentsV5(@QueryParam("pageNumber")int pageNumber,@DefaultValue("20")@QueryParam("pageSize")int pageSize); @GET @Path("/json/{id}") @Produces(MediaType.APPLICATION_JSON) Response getStudentInJson(@PathParam("id") int id); @GET @Path("/jsonp/{id}") @JSONP(callback="jsonp",queryParam="callback") @Produces("application/javascript") Response getStudentInJsonp(@PathParam("id") int id); @GET @Path("/xml/{id}") @Produces(MediaType.APPLICATION_XML) Response getStudentInXml(@PathParam("id") int id); @GET @Path("/{id}") Response getStudentInfo(@PathParam("id") int id); @DELETE @Path("/{id}") Response removeStudent(@PathParam("id") int id); @POST Response saveStudent(Student student); @PUT Response updateStudent(Student student);  }