@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; }
@RequestMapping(value = "/sach/add", method = RequestMethod.GET) public String hienThiThemSach(Model model) { List<TheLoaiSach> theLoaiSachs = theLoaiSachService.timDanhMucTheLoaiSach(); List<TheLoaiSachUI> theLoaiSachUIs = new ArrayList<TheLoaiSachUI>(); if (theLoaiSachs.size() > 0) { for (TheLoaiSach theLoaiSach : theLoaiSachs) { TheLoaiSachUI tLSachUIL = new TheLoaiSachUI(); tLSachUIL.setMaTheLoai(theLoaiSach.getMaTheLoai()); tLSachUIL.setTenTheLoai(theLoaiSach.getTenTheLoai()); theLoaiSachUIs.add(tLSachUIL); } } SachUI sachUI = new SachUI(); sachUI.setMaSach(UUID.randomUUID().toString()); model.addAttribute("theLoaiUIs", theLoaiSachUIs); model.addAttribute("sachUI", sachUI); model.addAttribute("btnName", "Thêm Sách Mới"); return WebConstant.views.THEM_SACH; }