Click here to Skip to main content
15,923,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Database:
table:
-books (bookId, bookName, author, publisher, publishingYear, price, quantity, CateId, bookClassId)
-bookclass (bookClassId, bookclassName)
-categories (cateId, cateName)
Spring - Controller
@Controller
public class ControllerBook {

IBookDaoImpl book;

@RequestMapping(value = "/", method = RequestMethod.GET)
public String viewWelcomePage(ModelMap map) {
book = new IBookDaoImpl();
List<books> book_list = book.findAll();
map.put("book_list", book_list);
return "home";
}

@RequestMapping(value = "/add", method = RequestMethod.GET)
public String viewAddNewPage(ModelMap map) {
Books bookForm = new Books();
map.addAttribute("bookForm", bookForm);
return "addBook";

}

@RequestMapping(value = "/add", method = RequestMethod.POST)
public String doAddNew( @ModelAttribute("bookForm") Books bookForm,
BindingResult result, ModelMap map) {

if (result.hasErrors()) {
map.addAttribute("bookForm", bookForm);
return "addBook";
}
book.saveOrUpdate(bookForm);

/**
* Get all titles
*/
List<books> book_list = book.findAll();
map.put("books_list", book_list);
map.addAttribute("add_success", "ok");
return "home";
}
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900