예제 #1
0
 /**
  * 获取图片列表
  *
  * @param since 指定起始时间,获取自该时刻至今所上传的图片
  */
 @ResponseBody
 @RequestMapping(value = "/get", method = RequestMethod.GET)
 public ResponseMessage get(Long since) {
   long myTime = since == null ? 0 : since;
   List<Pic> pics = picRepository.findSince(new Timestamp(myTime));
   List<Map<String, String>> items = new ArrayList<>();
   for (Pic pic : pics) {
     Map<String, String> item = new HashMap<>();
     item.put("title", pic.getTitle() == null ? "" : pic.getTitle());
     item.put("url", WebMvcConfig.getUrl(pic.getPath()));
     items.add(item);
   }
   return new ResponseMessage().set("items", JsonHelper.toJson(items));
 }
예제 #2
0
 /**
  * 上传图片文件,一次可以上传多张
  *
  * @param request 请求
  * @param files 照片文件
  * @throws IOException
  */
 @ResponseBody
 @RequestMapping(value = "/uploadMultiple", method = RequestMethod.POST)
 public ResponseMessage upload(
     HttpServletRequest request, @RequestParam(value = "img") MultipartFile[] files)
     throws IOException {
   List<String> filenames = new ArrayList<>();
   List<Pic> pics = new ArrayList<>();
   for (MultipartFile file : files) {
     Pair<String, String> pair = uploadImg(request, file);
     filenames.add(pair.getValue());
     Pic pic = Pic.newOne().setTitle(getTitle(pair.getKey(), "")).setPath(pair.getValue());
     pics.add(pic);
   }
   picRepository.save(pics);
   return new ResponseMessage()
       .set("count", String.valueOf(filenames.size()))
       .set("filenames", JsonHelper.toJson(filenames));
 }