版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/libra_ts/article/details/79500095
file的name为files
@RequestMapping ("/publish")
@ResponseBody
public WebJsonBean publish(@RequestParam MultipartFile[] files) throws IOException {
try {
for (int i = 0; i < files.length; i++) {
if (files[i].isEmpty()){
throw new MorningStarException(CODE.FAIL);
}
logger.info("upload path====>{}",path);
File fileout = new File(path);
if(!fileout.exists()){
fileout.getParentFile().mkdir();
fileout.mkdir();
}
file.transferTo(fileout);
}
} catch (IOException e) {
logger.info("文件上传异常", e);
}
return null;
}
重点
- 1.必须要判断文件夹是否存在
2.我记得以前是不要的判断的,不存在就默认创建,难道改了?
浪费了三小时,长记性………………