SpringMvc+Angularjs 实现多文件批量上传

本文通过实例代码给大家讲解了SpringMvc+Angularjs 实现多文件批量上传功能,非常不错,具有参考借鉴价值,需要的朋友一起学习吧

SpringMvc代码

jar包

commons-fileupload

commons-io

spring-mvc.xml配置

Controller

@RequestMapping(value = "api/v1/upload", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public Map upload (@RequestParam(value = "files") multipartfile [] files, @RequestParam(value = "id") String id, HttpServletRequest request, HttpServletResponse response) { Map res = new HashMap(); try { log.info("upload>>>>>id:{}", id); if (files!=null) { for (multipartfile file:files) { log.info("filename:{}", file.getoriginalFilename()); } } } catch (Exception e) { log.error("upload>>>>异常:{}", e.toString()); } log.info("upload>>>>返回结果:{}", res); return res; }

保存到本地

// copy File public boolean copyFile (multipartfile tempFile, String filePath) { Boolean res = false; try { File file = new File(filePath); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } // 将文件拷贝到当前目录下 tempFile.transferTo(file); res = true; } catch (Exception e) { log.info("copyFile>>>>异常:{}", e.toString()); } return res; }

AngularJs代码

Form表单提交

相关文章

HashMap是Java中最常用的集合类框架,也是Java语言中非常典型...
在EffectiveJava中的第 36条中建议 用 EnumSet 替代位字段,...
介绍 注解是JDK1.5版本开始引入的一个特性,用于对代码进行说...
介绍 LinkedList同时实现了List接口和Deque接口,也就是说它...
介绍 TreeSet和TreeMap在Java里有着相同的实现,前者仅仅是对...
HashMap为什么线程不安全 put的不安全 由于多线程对HashMap进...