浏览代码

!319 update ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java.
Merge pull request !319 from Hacker/N/A

若依 3 年之前
父节点
当前提交
6acfb0d5d9
共有 1 个文件被更改,包括 9 次插入10 次删除
  1. 9 10
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java

+ 9 - 10
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java

@@ -101,21 +101,20 @@ public class CommonController
     {
         try
         {
-         // 上传文件路径
+            // 上传文件路径
             String filePath = RuoYiConfig.getUploadPath();
-            String fileNames = "";
-            String urls = "";
-            for (MultipartFile file : files)
-            {
+            List<String> fileNames = new ArrayList<>();
+            List<String> urls = new ArrayList<>();
+            for (MultipartFile file : files) {
                 // 上传并返回新文件名称
                 String fileName = FileUploadUtils.upload(filePath, file);
                 String url = serverConfig.getUrl() + fileName;
-                fileNames += fileName + FILE_DELIMETER;
-                urls += url + FILE_DELIMETER;
+                fileNames.add(fileName);
+                urls.add(url);
             }
             AjaxResult ajax = AjaxResult.success();
-            ajax.put("fileNames", StringUtils.lastStringDel(fileNames, FILE_DELIMETER));
-            ajax.put("urls", StringUtils.lastStringDel(urls, FILE_DELIMETER));
+            ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER));
+            ajax.put("urls", StringUtils.join(urls, FILE_DELIMETER));
             return ajax;
         }
         catch (Exception e)
@@ -152,4 +151,4 @@ public class CommonController
             log.error("下载文件失败", e);
         }
     }
-}
+}