Exemplo n.º 1
0
 @POST
 public JsonObject saveBook(final JsonObject book) {
   long id = System.nanoTime();
   JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder();
   JsonObject newBook =
       jsonObjectBuilder
           .add("bookId", id)
           .add("bookName", book.get("bookName"))
           .add("publisher", book.get("publisher"))
           .build();
   BookResource.memoryBase.put(id, newBook);
   return newBook;
 }
Exemplo n.º 2
0
 static {
   memoryBase = com.google.common.collect.Maps.newHashMap();
   JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder();
   JsonObject newBook1 =
       jsonObjectBuilder
           .add("bookId", 1)
           .add("bookName", "Java Restful Web Services实战")
           .add("publisher", "机械工业出版社")
           .add("isbn", "9787111478881")
           .add("publishTime", "2014-09-01")
           .build();
   memoryBase.put(1L, newBook1);
   memoryBase.put(
       2L,
       jsonObjectBuilder
           .add("bookId", 2)
           .add("bookName", "JSF2和RichFaces4使用指南")
           .add("publisher", "电子工业出版社")
           .add("isbn", "9787121177378")
           .add("publishTime", "2012-09-01")
           .build());
   memoryBase.put(
       3L,
       jsonObjectBuilder
           .add("bookId", 3)
           .add("bookName", "Java EE 7 精髓")
           .add("publisher", "人民邮电出版社")
           .add("isbn", "9787115375483")
           .add("publishTime", "2015-02-01")
           .build());
   memoryBase.put(
       4L,
       jsonObjectBuilder
           .add("bookId", 4)
           .add("bookName", "Java Restful Web Services实战II")
           .add("publisher", "机械工业出版社")
           .build());
 }