@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("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"; }