コード例 #1
0
ファイル: DiaryController.java プロジェクト: xero07/project
  @RequestMapping("diary")
  public String diary(Model model, String c) {

    List<Diary> list = diaryDao.getDiaries();
    model.addAttribute("list", list);

    return "diary.diary";
  }
コード例 #2
0
ファイル: DiaryController.java プロジェクト: xero07/project
  @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";
  }
コード例 #3
0
ファイル: DiaryController.java プロジェクト: xero07/project
  @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";
  }
コード例 #4
0
ファイル: DiaryController.java プロジェクト: xero07/project
  @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";
  }
コード例 #5
0
ファイル: DiaryController.java プロジェクト: xero07/project
  @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";
  }