Пример #1
0
 @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;
 }
Пример #2
0
 @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);
 }
Пример #3
0
 @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);
 }
Пример #4
0
 @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;
 }
Пример #5
0
 private ModelAndView saveBook(Book book) {
   ModelAndView modelAndView = new ModelAndView("book");
   modelAndView.getModel().put("book", book);
   bookService.saveBook(book);
   return modelAndView;
 }
Пример #6
0
 @RequestMapping(value = "/book/get", method = RequestMethod.GET)
 public Iterable<Book> getAllBooks() {
   Iterable<Book> books = bookService.findAll();
   return books;
 }
Пример #7
0
 @RequestMapping(value = "/index", method = RequestMethod.GET)
 public ModelAndView index() {
   ModelMap model = new ModelMap();
   model.put("books", bookService.findAll());
   return new ModelAndView("books", model);
 }