예제 #1
0
 @RequestMapping("/edit/{contentId}")
 public ModelAndView edit(
     @PathVariable Long contentId, @Valid ContentRequest request, BindingResult result) {
   Content content = contentDAO.get(contentId);
   MultipartFile image = request.getCoverImg();
   if (image != null) {
     String fileType = FileUtil.getFileType(image.getOriginalFilename());
     String fileName =
         new StringBuilder().append(UUID.randomUUID()).append(".").append(fileType).toString();
     try {
       String path = CDNUtil.uploadFile(image.getInputStream(), fileName);
       content.setCoverImg(path);
     } catch (Exception e) {
       log.error("UploadFile Error.", e);
     }
   }
   content.setArticle(request.getArticle());
   content.setUpdated(new Date());
   content.setStatus(request.getStatus());
   content.setSynopsis(request.getSynopsis());
   content.setTitle(request.getTitle());
   content.setType(request.getType());
   contentDAO.update(content);
   return new ModelAndView("redirect:/content/detail/" + contentId);
 }
예제 #2
0
 @RequestMapping("/add")
 public ModelAndView add(@Valid ContentRequest request, BindingResult result) {
   MultipartFile image = request.getCoverImg();
   String path = StringUtils.EMPTY;
   if (image != null) {
     String fileType = FileUtil.getFileType(image.getOriginalFilename());
     String fileName =
         new StringBuilder().append(UUID.randomUUID()).append(".").append(fileType).toString();
     try {
       path = CDNUtil.uploadFile(image.getInputStream(), fileName);
     } catch (Exception e) {
       log.error("UploadFile Error.", e);
     }
   }
   Content content = new Content();
   content.setCoverImg(path);
   content.setAdminUserId(0L);
   content.setArticle(request.getArticle());
   content.setClicks(0L);
   Date time = new Date();
   content.setCreated(time);
   content.setUpdated(time);
   content.setStatus("inactive");
   content.setSynopsis(request.getSynopsis());
   content.setTitle(request.getTitle());
   content.setType(request.getType());
   contentDAO.save(content);
   return new ModelAndView("redirect:/content/detail/" + content.getId());
 }