@RequestMapping(value = "add", method = RequestMethod.POST) public String add( String name, String email, String tel, String cid, String password, MultipartFile photofile, Model model) throws Exception { String newFileName = null; if (photofile.getSize() > 0) { newFileName = MultipartHelper.generateFilename(photofile.getOriginalFilename()); File attachfile = new File(servletContext.getRealPath(SAVED_DIR) + "/" + newFileName); photofile.transferTo(attachfile); makeThumbnailImage( servletContext.getRealPath(SAVED_DIR) + "/" + newFileName, servletContext.getRealPath(SAVED_DIR) + "/s-" + newFileName + ".png"); } Student student = new Student(); student.setName(name); student.setEmail(email); student.setTel(tel); student.setCid(cid); student.setPassword(password); student.setPhoto(newFileName); studentDao.insert(student); return "redirect:list.do"; }
@RequestMapping(value = "add", method = RequestMethod.POST) public String add(Cook cook, MultipartFile file) throws Exception { if (file.getSize() > 0) { String newFileName = MultipartHelper.generateFilename(file.getOriginalFilename()); File attachfile = new File(servletContext.getRealPath(SAVED_DIR) + "/" + newFileName); file.transferTo(attachfile); cook.setAttachFile(newFileName); makeThumbnailImage( servletContext.getRealPath(SAVED_DIR) + "/" + newFileName, servletContext.getRealPath(SAVED_DIR) + "/s-" + newFileName + ".png"); } cookService.insert(cook); return "redirect:list.do"; }
@RequestMapping("update") public String update( String name, String email, String tel, String cid, String photo, MultipartFile photofile, Model model) throws Exception { String newFileName = null; if (photofile.getSize() > 0) { newFileName = MultipartHelper.generateFilename(photofile.getOriginalFilename()); File attachfile = new File(servletContext.getRealPath(SAVED_DIR) + "/" + newFileName); photofile.transferTo(attachfile); makeThumbnailImage( servletContext.getRealPath(SAVED_DIR) + "/" + newFileName, servletContext.getRealPath(SAVED_DIR) + "/s-" + newFileName + ".png"); } Student student = new Student(); student.setName(name); student.setEmail(email); student.setTel(tel); student.setCid(cid); if (newFileName != null) { student.setPhoto(newFileName); } else if (newFileName == null && photo.length() > 0) { student.setPhoto(photo); } if (studentDao.update(student) <= 0) { model.addAttribute("errorCode", "401"); return "student/StudentAuthError"; } return "redirect:list.do"; }
@RequestMapping(value = "update", method = RequestMethod.POST) public String update(Cook cook, MultipartFile file, Model model) throws Exception { if (file.getSize() > 0) { String newFileName = MultipartHelper.generateFilename(file.getOriginalFilename()); File attachfile = new File(servletContext.getRealPath(SAVED_DIR) + "/" + newFileName); file.transferTo(attachfile); cook.setAttachFile(newFileName); makeThumbnailImage( servletContext.getRealPath(SAVED_DIR) + "/" + newFileName, servletContext.getRealPath(SAVED_DIR) + "/s-" + newFileName + ".png"); } else if (cook.getAttachFile().length() == 0) { cook.setAttachFile(null); } if (cookService.update(cook) <= 0) { model.addAttribute("errorCode", "401"); return "cook/BoardAuthError"; } return "redirect:list.do"; }