コード例 #1
0
  /** Simply selects the home view to render by returning its name. */
  @RequestMapping(value = "/books", method = RequestMethod.GET)
  public @ResponseBody String getAllBooks() {
    logger.info("Inside getAllBooks() method...");

    StringBuilder stringBuilder = new StringBuilder();
    List<Book> allBooks = bookRepository.getAllBooks();
    for (Book book : allBooks) {
      stringBuilder.append(book.toString());
    }

    return stringBuilder.toString();
  }
コード例 #2
0
  @RequestMapping(
      value = "/book/add",
      method = RequestMethod.GET,
      produces = {APPLICATION_JSON})
  public @ResponseBody String addBook() {

    Book book1 = new Book();
    book1.setActive(true);
    book1.setAuthor("Sasha");
    book1.setDescription(new Date().toString());
    book1.setTitle("testBook");

    bookRepository.addBook(book1);

    return "added book:" + book1.getTitle();
  }