@RequestMapping(value = "diaryDelete", method = RequestMethod.POST) public String diaryDelete(String c, String dc) { diaryDao.removeDiary(c); if (c.equals(dc)) { diaryImageDao.removeDiaryImage(dc); } return "redirect:diary"; }
@RequestMapping("diaryDetail") public String diaryDetail(String c, Model model) { DiaryImage di = diaryImageDao.getDiaryImage(c); Diary d = diaryDao.getDiary(c); model.addAttribute("d", d); model.addAttribute("di", di); return "diary.diaryDetail"; }
@RequestMapping(value = "diaryUdtReg", method = RequestMethod.GET) public String diaryUdtReg(String c, Model model) { DiaryImage di = diaryImageDao.getDiaryImage(c); Diary d = diaryDao.getDiary(c); model.addAttribute("d", d); model.addAttribute("di", di); return "diary.diaryUdtReg"; }
@RequestMapping(value = "diaryReg", method = RequestMethod.POST) public String diaryReg( Diary d, MultipartFile file, Principal principal, HttpServletRequest request) throws IOException { d.setMemberId(principal.getName()); diaryDao.addDiary(d); if (!file.isEmpty()) { ServletContext application = request.getServletContext(); String url = "/resource/upload/diary"; String path = application.getRealPath(url); String temp = file.getOriginalFilename(); String fname = temp.substring(temp.lastIndexOf('\\') + 1); String fpath = path + "\\" + fname; InputStream ins = file.getInputStream(); OutputStream outs = new FileOutputStream(fpath); // ÀúÀå byte[] bigData = new byte[1024]; int len = 0; while ((len = ins.read(bigData, 0, 1024)) >= 0) outs.write(bigData, 0, len); outs.flush(); outs.close(); ins.close(); DiaryImage diaryImage = new DiaryImage(); diaryImage.setName(fname); diaryImage.setDiaryCode(diaryDao.getLastCode()); diaryImageDao.addDiaryImage(diaryImage); } return "redirect:diary"; }