@Value("${file.project_filepath}") private String projectFilePath; @PostMapping("/uplaod") public BaseResult upload(@RequestParam("file") MultipartFile file){ if(file.isEmpty()){ return BaseResult.error("上传失败"); } String fileName = file.getOriginalFilename(); int size = (int) file.getSize(); System.out.println(fileName + "-->" + size); // String path = "d:/dg" ; File dest = new File(projectFilePath + fileName); if(!dest.getParentFile().exists()){ //判断文件父目录是否存在 dest.getParentFile().mkdir(); } try { file.transferTo(dest); //保存文件 return BaseResult.ok("保存成功"); } catch (IllegalStateException e) { e.printStackTrace(); return BaseResult.error("保存失败"); } catch (IOException e) { e.printStackTrace(); return BaseResult.error("操作失败"); } }