Pārlūkot izejas kodu

2024-10-30 update board write & board modify

junggilpark 9 mēneši atpakaļ
vecāks
revīzija
61bb1ed28d

+ 23 - 12
src/main/java/com/its/web/service/notice/NoticeService.java

@@ -131,7 +131,7 @@ public class NoticeService {
         paramMap.put("bContent", param.getBcontent());
         paramMap.put("bSubject", param.getBsubject());
         paramMap.put("webUserId", webUserId);
-
+        log.info("{}",attachFile);
         if (attachFile != null && attachFile.size() > 0){
 
             for (MultipartFile file : attachFile) {
@@ -153,16 +153,23 @@ public class NoticeService {
         }
 
         if (success.equals("S")) {
-            int fileSize = attachFile.size();
+            if (attachFile != null) {
+                int fileSize = attachFile.size();
 
-            if (fileSize == 1) {
-                fileNames = fileNames + "|";
-                fileIds = fileIds + "|";
+                if (attachFile != null && fileSize == 1) {
+                    fileNames = fileNames + "|";
+                    fileIds = fileIds + "|";
+                }
+                else if (fileSize == 3) {
+                    fileNames = fileNames.substring(fileNames.length() - 1);
+                    fileIds = fileIds.substring(fileIds.length() - 1);
+                }
             }
-            else if (fileSize == 3) {
-                fileNames = fileNames.substring(fileNames.length() - 1);
-                fileIds = fileIds.substring(fileIds.length() - 1);
+            else {
+                fileNames = "||";
+                fileIds = "||";
             }
+
             paramMap.put("attachFile", fileNames);
             paramMap.put("attachFileId", fileIds);
             int affectedRows = this.mapper.insertNotice(paramMap);
@@ -188,7 +195,6 @@ public class NoticeService {
         String message = "작성하신 게시물이 수정되었습니다.";
 
         NoticeDto dto = this.findNotice(param.getBoardNo());
-
         if (dto != null) {
             if (!attachFileNames.equals(dto.getAttachFile())) {
                 String originAttachFile = dto.getAttachFile();
@@ -251,10 +257,15 @@ public class NoticeService {
                 }
             }
 
-            if (sameIndex.size() == 3) {
-                fileId = sameIndex.get(0) + "|" +sameIndex.get(1) + "|" + sameIndex.get(2);
+            fileId = "";
+            for (int ii = 0; ii < 3; ii++) {
+                if (sameIndex.get(ii) != null) {
+                    fileId += sameIndex.get(ii);
+                }
+                if (ii != 2) {
+                    fileId += "|";
+                }
             }
-
         }
 
         paramMap.put("attachFile", attachFileNames);

+ 1 - 3
src/main/resources/templates/admin/notice-view.html

@@ -231,9 +231,7 @@
         formData.append("bContent", content);
 
         if (file && file.name) {
-            formData.append("attachFileNames", file.name + "|" + file.name + "|" + file.name);
-            formData.append("attachFile", file);
-            formData.append("attachFile", file);
+            formData.append("attachFileNames", file.name + "||");
             formData.append("attachFile", file);
         }
         else {

+ 1 - 0
src/main/resources/templates/admin/notice-write.html

@@ -124,6 +124,7 @@
             formData.append("attachFile", file);
         }
 
+        console.log(file);
         $.ajax({
             url: '/api/notice/writeNotice',
             processData : false,