「Struts2入門」@Path、 @GET、@POST、 @DELETEでRestEasyを実装するサンプルコード

Javaコード:
@Path(“/library")
public class LibDemo {
@GET
@Path(“/books")
public String getBooks() {
//some code
}
@GET
@Path(“/book/{isbn}")
public String getBook(@PathParam(“isbn") String id) {
// 処理コード
}
@PUT
@Path(“/book/{isbn}")
public void addBook(@PathParam(“isbn") String id, @QueryParam(“name") String name) {
//some code
}

@DELETE
@Path(“/book/{id}")
public void removeBook(@PathParam(“id") String id {
// some code
}

}

LibDemoクラスのリクエスト
GET http://cfthost.com/services/library/books
GET http://cfthost.com/services/library/book/12345
PUT http://cfthost.com/services/library/book/12345
DELETE http://cfthost.com/services/library/book/12345

Java

Posted by arkgame