@Test public void testGetAll(){ Response response = target("student").path("all").request().get(); System.out.println(response.getStatus()); System.out.println(response.readEntity(String.class)); System.out.println("----------------------------------------------"); response = target("student").path("all").queryParam("callback", "callback").request("application/javascript").get(); System.out.println(response.getStatus()); System.out.println(response.readEntity(String.class)); }
@GET @Path("all") @JSONP(callback="jsonp",queryParam="callback") @Produces({MediaType.APPLICATION_JSON,"application/javascript"}) public List<Student> getAll(){ List<Student> students = new ArrayList<Student>(); Student student; ClassRoom classRoom; for (int i = 1; i <= 100; i++) { student = new Student(); classRoom = new ClassRoom(i, "classRoom"+i); student.setSid(i); student.setSname("student"+i); student.setDate(Calendar.getInstance().getTime()); student.setClsssRoom(classRoom); students.add(student); } return students; }
StudentRestService { @GET @Path("all") @JSONP(callback="jsonp",queryParam="callback") @Produces({MediaType.APPLICATION_JSON,"application/javascript"}) public List<Student> getAll(){ List<Student> students = new ArrayList<Student>(); Student student; ClassRoom classRoom; for (int i = 1; i <= 100; i++) { student = new Student(); classRoom = new ClassRoom(i, "classRoom"+i); student.setSid(i); student.setSname("student"+i); student.setDate(Calendar.getInstance().getTime()); student.setClsssRoom(classRoom); students.add(student); } return students; } }
StudentRestService { @GET @Path("all") @JSONP(callback="jsonp",queryParam="callback") @Produces({MediaType.APPLICATION_JSON,"application/javascript"}) public List<Student> getAll(){ List<Student> students = new ArrayList<Student>(); Student student; ClassRoom classRoom; for (int i = 1; i <= 100; i++) { student = new Student(); classRoom = new ClassRoom(i, "classRoom"+i); student.setSid(i); student.setSname("student"+i); student.setDate(Calendar.getInstance().getTime()); student.setClsssRoom(classRoom); students.add(student); } return students; }  }
StudentRestService { @GET @Path("all") @JSONP(callback="jsonp",queryParam="callback") @Produces({MediaType.APPLICATION_JSON,"application/javascript"}) public List<Student> getAll(){ List<Student> students = new ArrayList<Student>(); Student student; ClassRoom classRoom; for (int i = 1; i <= 100; i++) { student = new Student(); classRoom = new ClassRoom(i, "classRoom"+i); student.setSid(i); student.setSname("student"+i); student.setDate(Calendar.getInstance().getTime()); student.setClsssRoom(classRoom); students.add(student); } return students; }  @GET @Path("all") @JSONP(callback="jsonp",queryParam="callback") @Produces({MediaType.APPLICATION_JSON,"application/javascript"}) List<Student> getAll(); @GET @Path("/{id}") @JSONP(callback="jsonp",queryParam="callback") @Produces({MediaType.APPLICATION_JSON,"application/javascript"}) Student getStudent(@PathParam("id")int id); @POST @JSONP(callback="jsonp",queryParam="callback") @Consumes(MediaType.APPLICATION_JSON) @Produces({MediaType.APPLICATION_JSON,"application/javascript"}) Student saveStudent(Student student); @PUT @JSONP(callback="jsonp",queryParam="callback") @Consumes(MediaType.APPLICATION_JSON) @Produces({MediaType.APPLICATION_JSON,"application/javascript"}) Student updateStudent(Student student); @DELETE @Path("{id}") @JSONP(callback="jsonp",queryParam="callback") @Consumes(MediaType.APPLICATION_JSON) @Produces({MediaType.APPLICATION_JSON,"application/javascript"}) Response deleteStudent(@PathParam("id")int id,@Context UriInfo uriInfo); }
StudentRestService { @GET @Path("all") @JSONP(callback="jsonp",queryParam="callback") @Produces({MediaType.APPLICATION_JSON,"application/javascript"}) public List<Student> getAll(){ List<Student> students = new ArrayList<Student>(); Student student; ClassRoom classRoom; for (int i = 1; i <= 100; i++) { student = new Student(); classRoom = new ClassRoom(i, "classRoom"+i); student.setSid(i); student.setSname("student"+i); student.setDate(Calendar.getInstance().getTime()); student.setClsssRoom(classRoom); students.add(student); } return students; }  @GET @Path("all") @JSONP(callback="jsonp",queryParam="callback") @Produces({MediaType.APPLICATION_JSON,"application/javascript"}) List<Student> getAll(); @GET @Path("/{id}") @JSONP(callback="jsonp",queryParam="callback") @Produces({MediaType.APPLICATION_JSON,"application/javascript"}) Student getStudent(@PathParam("id")int id); @POST @JSONP(callback="jsonp",queryParam="callback") @Consumes(MediaType.APPLICATION_JSON) @Produces({MediaType.APPLICATION_JSON,"application/javascript"}) Student saveStudent(Student student); @PUT @JSONP(callback="jsonp",queryParam="callback") @Consumes(MediaType.APPLICATION_JSON) @Produces({MediaType.APPLICATION_JSON,"application/javascript"}) Student updateStudent(Student student); @DELETE @Path("{id}") @JSONP(callback="jsonp",queryParam="callback") @Consumes(MediaType.APPLICATION_JSON) @Produces({MediaType.APPLICATION_JSON,"application/javascript"}) Response deleteStudent(@PathParam("id")int id,@Context UriInfo uriInfo);  }