@RequestMapping(method = RequestMethod.GET, value = "/{userid}/books/new") public ModelAndView addNewBook(@PathVariable("userid") String userid) { Book book = new Book(); book.setUserId(Integer.parseInt(userid)); ModelAndView modelAndView = new ModelAndView("books/new"); modelAndView.addObject("book", book); modelAndView.addObject("userid", userid); return modelAndView; }
@RequestMapping(method = RequestMethod.POST, value = "/{userid}/books") public String saveUserBook(@PathVariable("userid") String userid, HttpServletRequest request) { Book book = new Book(); book.setUserId(Integer.parseInt(userid)) .setAuthor(request.getParameter("author")) .setImage(request.getParameter("image")) .setSummary(request.getParameter("summary")) .setTitle(request.getParameter("title")); bookService.saveUserBook(book); return "redirect:/users/" + userid + "/books"; }