package com.test.test;import java.io.File;
import java.io.IOException;import java.util.ArrayList;
import java.util.HashMap;import java.util.List;
import java.util.Map;import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;import org.springframework.web.multipart.MultipartFile;
import cn.com.taiji.common.manager.ManagerException;
public class TestUploadFile
{
/***
* @param multipartFiles 多文件上传流
* @param request request请求
* @param savePath 保存路径
* @return 返回包括文件名称、文件路径组成的map集合的list集合
* @throws IllegalStateException
* @throws IOException
* @throws ManagerException
*/public List> uploadFile(MultipartFile[] multipartFiles, HttpServletRequest request, String savePath) throws IllegalStateException, IOException, ManagerException
{
List> fileList = new ArrayList<>();
ServletContext servletContext = request.getServletContext();
for (MultipartFile multipartFile : multipartFiles)
{MapfileMap = new HashMap();
if (multipartFile!=null&&multipartFile.getSize()!=0)
{ String imageName = multipartFile.getOriginalFilename();
String path = servletContext.getRealPath(savePath)+imageName;
File file=new File(path);
multipartFile.transferTo(file);
fileMap.put("fileName", imageName);
fileMap.put("savePath", savePath); }
fileList.add(fileMap); }
return fileList;
} }