public String handleFileUpload(HttpServletRequest request,@RequestParam("names") String[] name) {
MultipartHttpServletRequest params = ((MultipartHttpServletRequest) request);
List<MultipartFile> files = params.getFiles("file");
System.out.println("files" + files);
//接收前端传过来的字段
MultipartFile file = null;
//先设置一个数组来装file路径
List jars = new ArrayList();
//设置文件路径
final String firstPathName = addressConfig.getFirstPath();
for (int i = 0; i < files.size(); ++i) {
file = files.get(i);
if (!file.isEmpty()) {
try {
byte[] bytes = file.getBytes();
// 获取文件名
String origFileName = file.getOriginalFilename();
//文件路径
Path path = Paths.get(firstPathName + origFileName);
System.out.println("lj: " + path);
jars.add(path);
//如果没有files文件夹,则创建
if (!Files.isWritable(path)) {
Files.createDirectories(Paths.get(firstPathName));
}
//文件写入指定路径
Files.write(path, bytes);
}
} catch (Exception e) {
return "文件上传失败 " + i + " => " + e.getMessage();
}
} else {
return "文件上传失败 " + i + " because the file was empty.";
}
System.out.println("mz:" + name[i]);
}
return "文件上传成功";
}
```**_用数组_**