예제 #1
0
 /** 功能:添加修改 */
 @RequestMapping(value = "/save", method = RequestMethod.POST)
 public ModelAndView save(@RequestParam MultipartFile[] images, String gid) throws Exception {
   ModelAndView mav =
       new ModelAndView(com.baofeng.utils.Constants.COREWEB_BUILDITEMS + "/musicbg");
   MusicBg music = new MusicBg();
   if (images != null && images.length > 0) {
     for (MultipartFile $file : images) {
       if (!$file.isEmpty()) {
         String name = $file.getOriginalFilename();
         String ext = name.substring(name.lastIndexOf("."), name.length());
         String sha1 = DigestUtils.shaHex($file.getInputStream());
         String fileName = sha1 + ext;
         String path =
             Constants.DEFAULT_UPLOADIMAGEPATH + File.separator + Constants.sha1ToPath(sha1);
         Constants.mkdirs(path);
         FileUtils.copyInputStreamToFile($file.getInputStream(), new File(path, fileName));
         music.setImageSha1(sha1);
         music.setImage(fileName);
       }
     }
   }
   this.musicBgService.addMusicBg(music, gid);
   WeekService week = this.weekServiceService.readWeekService(gid);
   if (week != null) {
     mav.addObject("week", week);
   }
   return mav;
 }
예제 #2
0
 /** 功能:修改图片 */
 @ResponseBody
 @RequestMapping(value = "/upLoadImages", method = RequestMethod.POST)
 public ResultMsg upLoadImages(String id2, @RequestParam MultipartFile[] images2, String gid)
     throws Exception {
   ResultMsg result = new ResultMsg();
   result.setResultMessage("errors");
   MusicBg music = new MusicBg();
   if (images2 != null && images2.length > 0) {
     for (MultipartFile $file : images2) {
       if (!$file.isEmpty()) {
         String name = $file.getOriginalFilename();
         String ext = name.substring(name.lastIndexOf("."), name.length());
         String sha1 = DigestUtils.shaHex($file.getInputStream());
         String fileName = sha1 + ext;
         String path =
             Constants.DEFAULT_UPLOADIMAGEPATH + File.separator + Constants.sha1ToPath(sha1);
         Constants.mkdirs(path);
         FileUtils.copyInputStreamToFile($file.getInputStream(), new File(path, fileName));
         music.setImageSha1(sha1);
         music.setImage(fileName);
       }
     }
   }
   music.setId(id2);
   if (this.musicBgService.addMusicBg(music, gid)) {
     result.setResultMessage("success");
   }
   return result;
 }