java面试题中常见编程题有哪些,SpringBoot上传文件到后端服务器,Java笔试题编程题

avatar
作者
猴君
阅读量: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

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!