@Test public void testGetStudent(){ Response response = target("student").path("1").request().get(); System.out.println(response.getStatus()); System.out.println(response.readEntity(String.class)); System.out.println("----------------------------------------------"); response = target("student").path("1").queryParam("callback", "callback").request("application/javascript").get(); System.out.println(response.getStatus()); System.out.println(response.readEntity(String.class)); }
@GET @Path("/{id}") @JSONP(callback="jsonp",queryParam="callback") @Produces({MediaType.APPLICATION_JSON,"application/javascript"}) public Student getStudent(@PathParam("id")int id){ Student student = new Student(); ClassRoom classRoom = new ClassRoom(id, "classRoom"+id); student.setSid(id); student.setSname("student"+id); student.setDate(Calendar.getInstance().getTime()); student.setClsssRoom(classRoom); return student; }
StudentRestService { @GET @Path("/{id}") @JSONP(callback="jsonp",queryParam="callback") @Produces({MediaType.APPLICATION_JSON,"application/javascript"}) public Student getStudent(@PathParam("id")int id){ Student student = new Student(); ClassRoom classRoom = new ClassRoom(id, "classRoom"+id); student.setSid(id); student.setSname("student"+id); student.setDate(Calendar.getInstance().getTime()); student.setClsssRoom(classRoom); return student; } }
StudentRestService { @GET @Path("/{id}") @JSONP(callback="jsonp",queryParam="callback") @Produces({MediaType.APPLICATION_JSON,"application/javascript"}) public Student getStudent(@PathParam("id")int id){ Student student = new Student(); ClassRoom classRoom = new ClassRoom(id, "classRoom"+id); student.setSid(id); student.setSname("student"+id); student.setDate(Calendar.getInstance().getTime()); student.setClsssRoom(classRoom); return student; }  }
StudentRestService { @GET @Path("/{id}") @JSONP(callback="jsonp",queryParam="callback") @Produces({MediaType.APPLICATION_JSON,"application/javascript"}) public Student getStudent(@PathParam("id")int id){ Student student = new Student(); ClassRoom classRoom = new ClassRoom(id, "classRoom"+id); student.setSid(id); student.setSname("student"+id); student.setDate(Calendar.getInstance().getTime()); student.setClsssRoom(classRoom); return student; }  @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("/{id}") @JSONP(callback="jsonp",queryParam="callback") @Produces({MediaType.APPLICATION_JSON,"application/javascript"}) public Student getStudent(@PathParam("id")int id){ Student student = new Student(); ClassRoom classRoom = new ClassRoom(id, "classRoom"+id); student.setSid(id); student.setSname("student"+id); student.setDate(Calendar.getInstance().getTime()); student.setClsssRoom(classRoom); return student; }  @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);  }