javax.ws.rs.POST(PUT、GET、DELETE)でRESTful API を実装するサンプル
サンプルコード
/**データ追加 */
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public BookBean postData(BookBean bean) throws SQLException {
String strSql ="insert into tablename(xxxx";
//some code
}
/**データ更新 */
@PUT
@Path("user")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public BookBean updateData(BookBean bean) throws SQLException {
String strSql ="update tablename set xxxxx";
//some code
}
/**データ検索 */
@GET
@Path("{bookId}")
@Produces(MediaType.APPLICATION_JSON)
public List<BookBean>selectByBookId(@PathParam("bookId") int bookId)
throws SQLException {
String strSql =" select * from tablename where xxx";
//some code
}