From 9589d7010f1c8cd427e80e896bae686f4c567bda Mon Sep 17 00:00:00 2001 From: ronger Date: Wed, 26 Aug 2020 09:19:22 +0800 Subject: [PATCH] =?UTF-8?q?:mag:=20=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/api/common/UploadController.java | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) 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