@RequestMapping(value = "/book/delete/{isbn}", method = RequestMethod.GET) public ModelAndView delete(@PathVariable String isbn) { if (bookService.getBookByIsbn(isbn) == null) { return getErrorView("This book is not exist"); } bookService.delete(isbn); ModelAndView modelAndView = new ModelAndView("books"); modelAndView.getModel().put("books", bookService.findAll()); return modelAndView; }
@RequestMapping(value = "/book/update", method = RequestMethod.POST) public ModelAndView doUpdate(Book book) { if (bookService.getBookByIsbn(book.getIsbn()) == null) { return getErrorView("This book is not exist."); } return saveBook(book); }
@RequestMapping(value = "/book/add", method = RequestMethod.POST) public ModelAndView doAdd(Book book) { if (bookService.getBookByIsbn(book.getIsbn()) != null) { return getErrorView("This Book is exist."); } return saveBook(book); }
@RequestMapping(value = "/book/update/{isbn}", method = RequestMethod.GET) public ModelAndView update(@PathVariable String isbn) { Book book = bookService.getBookByIsbn(isbn); if (book == null) { return getErrorView("This book is not exist."); } ModelAndView modelAndView = new ModelAndView("updateBook"); modelAndView.getModel().put("book", book); return modelAndView; }
private ModelAndView saveBook(Book book) { ModelAndView modelAndView = new ModelAndView("book"); modelAndView.getModel().put("book", book); bookService.saveBook(book); return modelAndView; }
@RequestMapping(value = "/book/get", method = RequestMethod.GET) public Iterable<Book> getAllBooks() { Iterable<Book> books = bookService.findAll(); return books; }
@RequestMapping(value = "/index", method = RequestMethod.GET) public ModelAndView index() { ModelMap model = new ModelMap(); model.put("books", bookService.findAll()); return new ModelAndView("books", model); }