@ApiOperation(value = "文件上传")
@PostMapping(value = "/upload", headers = "content-type=multipart/form-data")
public String upload(@RequestParam("file") MultipartFile file) {
if (file.isEmpty()) {
log.warn("文件为空");
return "上传失败,请选择文件";
}
try {
file.transferTo(new File(savePath + file.getOriginalFilename()));
return "文件上传成功";
} catch (IOException e) {
return "文件上传失败";
}
}
<form action="/file/upload" method="post" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit">
</form>
原文:https://www.cnblogs.com/circle-coder/p/14816584.html