阅读量:0
@ResponseBody
public String uploadFiles(@RequestPart MultipartFile file) {
String fileName = file.getOriginalFilename();
System.out.println("开始上传文件 " + fileName);
long cnt = 0;
try {
cnt = storageService.save(file, uploadFilePath);
} catch (Exception e) {
e.printStackTrace();
}
return "上传字节数 " + cnt;
}
@GetMapping(“/delete_file”)
@ResponseBody
public String deleteFile() {
storageService.deleteAll(Path.of(uploadFilePath));
return “删除完成”;
}
}
在FileUploadController里面用到了my_file_upload.html,my_file_upload.html需要放在resources/templates下面,my_file_upload.html代码内容:
my_file_upload.html里面的action="/do_upload_action"对应于FileUploadController中的uploadFiles()函数。
最后,在application.p