diff --git a/src/main/java/com/rymcu/vertical/web/api/common/UploadController.java b/src/main/java/com/rymcu/vertical/web/api/common/UploadController.java index f8f9ddf..7c8348e 100644 --- a/src/main/java/com/rymcu/vertical/web/api/common/UploadController.java +++ b/src/main/java/com/rymcu/vertical/web/api/common/UploadController.java @@ -25,6 +25,7 @@ import java.util.Set; /** * 文件上传控制器 + * * @author ronger */ @RestController @@ -36,22 +37,22 @@ public class UploadController { public static final String ctxHeadPicPath = "/usr/local/src/nebula/static"; @PostMapping("/file") - public GlobalResult uploadPicture(@RequestParam(value = "file", required = false) MultipartFile multipartFile,@RequestParam(defaultValue = "1")Integer type, HttpServletRequest request){ + public GlobalResult uploadPicture(@RequestParam(value = "file", required = false) MultipartFile multipartFile, @RequestParam(defaultValue = "1") Integer type, HttpServletRequest request) { if (multipartFile == null) { return GlobalResultGenerator.genErrorResult("请选择要上传的文件"); } String typePath = getTypePath(type); //图片存储路径 - String dir = ctxHeadPicPath+"/"+typePath; + String dir = ctxHeadPicPath + "/" + typePath; File file = new File(dir); if (!file.exists()) { file.mkdirs();// 创建文件根目录 } - String localPath = Utils.getProperty("resource.file-path")+"/"+typePath+"/"; + String localPath = Utils.getProperty("resource.file-path") + "/" + typePath + "/"; String orgName = multipartFile.getOriginalFilename(); - String fileName = System.currentTimeMillis()+"."+ FileUtils.getExtend(orgName).toLowerCase(); + String fileName = System.currentTimeMillis() + "." + FileUtils.getExtend(orgName).toLowerCase(); String savePath = file.getPath() + File.separator + fileName; @@ -59,7 +60,7 @@ public class UploadController { File saveFile = new File(savePath); try { FileCopyUtils.copy(multipartFile.getBytes(), saveFile); - data.put("url", localPath+fileName); + data.put("url", localPath + fileName); } catch (IOException e) { data.put("message", "上传失败!"); } @@ -68,43 +69,43 @@ public class UploadController { } @PostMapping("/file/batch") - public GlobalResult batchFileUpload(@RequestParam(value = "file[]", required = false)MultipartFile[] multipartFiles,@RequestParam(defaultValue = "1")Integer type,HttpServletRequest request){ + public GlobalResult batchFileUpload(@RequestParam(value = "file[]", required = false) MultipartFile[] multipartFiles, @RequestParam(defaultValue = "1") Integer type, HttpServletRequest request) { String typePath = getTypePath(type); //图片存储路径 - String dir = ctxHeadPicPath+"/"+typePath; + String dir = ctxHeadPicPath + "/" + typePath; File file = new File(dir); if (!file.exists()) { file.mkdirs();// 创建文件根目录 } - String localPath = Utils.getProperty("resource.file-path")+"/"+typePath+"/"; + String localPath = Utils.getProperty("resource.file-path") + "/" + typePath + "/"; Map succMap = new HashMap(10); Set errFiles = new HashSet(); - for(int i=0,len=multipartFiles.length;i