@RequestMapping(value = "/sach/list", method = RequestMethod.GET) public String hienThiDanhMucSach(Model model) { List<Sach> sachs = sachService.timTatCaCuonSach(); List<SachUI> sachUIs = SachMapper.convertToListSachUI(sachs); model.addAttribute("sachUIs", sachUIs); return WebConstant.views.DANH_MUC_SACH; }
@RequestMapping(value = "/sach/add", method = RequestMethod.POST) public String create(SachUI sachUI, Model model) { TheLoaiSach theLoaiSach = theLoaiSachService.timTheLoaiSachByTen(sachUI.getTheLoaiUI()); if (theLoaiSach != null) { Sach sach = SachMapper.convertToSach(sachUI, theLoaiSach); sachService.saveOrUpdate(sach); } return "redirect:/sach/list"; }
@RequestMapping(value = "/sach/edit", method = RequestMethod.GET) public String hienThiSuaSach( @RequestParam(value = "maSach", required = true) String maSach, Model model) { Sach sachExisting = sachService.timSachByMaSach(maSach); if (sachExisting != null) { SachUI sachUI = SachMapper.convertToSachUI(sachExisting); model.addAttribute("sachUI", sachUI); List<TheLoaiSach> tLSs = theLoaiSachService.timDanhMucTheLoaiSach(); List<TheLoaiSachUI> tLSUIs = TheLoaiSachMapper.convertToListTheLoaiSachUI(tLSs); model.addAttribute("theLoaiUIs", tLSUIs); } model.addAttribute("btnName", "Sửa Thông Tin Sách"); return WebConstant.views.THEM_SACH; }