diff --git a/VamPa/src/main/java/com/vam/controller/AdminController.java b/VamPa/src/main/java/com/vam/controller/AdminController.java index 08f5632..dd8a8dd 100644 --- a/VamPa/src/main/java/com/vam/controller/AdminController.java +++ b/VamPa/src/main/java/com/vam/controller/AdminController.java @@ -1,5 +1,8 @@ package com.vam.controller; +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.List; import org.slf4j.Logger; @@ -11,6 +14,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.mvc.support.RedirectAttributes; import com.fasterxml.jackson.core.JsonProcessingException; @@ -261,4 +265,39 @@ public class AdminController { model.addAttribute("pageMaker", new PageDTO(cri, authorService.authorGetTotal(cri))); } + /* 첨부 파일 업로드 */ + @PostMapping("/uploadAjaxAction") + public void uploadAjaxActionPOST(MultipartFile[] uploadFile) { + + logger.info("uploadAjaxActionPOST.........."); + String uploadFolder = "C:\\upload"; + + /* 날짜 폴더 경로 */ + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + + Date date = new Date(); + + String str = sdf.format(date); + + String datePath = str.replace("-", File.separator); + + /* 폴더 생성 */ + File uploadPath = new File(uploadFolder, datePath); + + if(uploadPath.exists() == false) { + uploadPath.mkdirs(); + } + + + + // 향상된 for + for(MultipartFile multipartFile : uploadFile) { + + } + + + + + } + } diff --git a/VamPa/src/main/webapp/WEB-INF/views/admin/goodsEnroll.jsp b/VamPa/src/main/webapp/WEB-INF/views/admin/goodsEnroll.jsp index 1e1d098..69e04c1 100644 --- a/VamPa/src/main/webapp/WEB-INF/views/admin/goodsEnroll.jsp +++ b/VamPa/src/main/webapp/WEB-INF/views/admin/goodsEnroll.jsp @@ -484,6 +484,7 @@ $("#enrollBtn").on("click",function(e){ /* 이미지 업로드 */ $("input[type='file']").on("change", function(e){ + let formData = new FormData(); let fileInput = $('input[name="uploadFile"]'); let fileList = fileInput[0].files; let fileObj = fileList[0]; @@ -492,7 +493,17 @@ $("#enrollBtn").on("click",function(e){ return false; } - alert("통과"); + formData.append("uploadFile", fileObj); + + $.ajax({ + url: '/admin/uploadAjaxAction', + processData : false, + contentType : false, + data : formData, + type : 'POST', + dataType : 'json' + }); + }); diff --git a/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties b/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties index 338cac8..f353d42 100644 --- a/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties +++ b/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven Integration for Eclipse -#Wed Apr 28 02:05:10 KST 2021 +#Mon May 10 05:22:44 KST 2021 m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa m2e.projectName=VamPa groupId=com.vam diff --git a/VamPa_MySQL/src/main/java/com/vam/controller/AdminController.java b/VamPa_MySQL/src/main/java/com/vam/controller/AdminController.java index 1f8ae24..220614d 100644 --- a/VamPa_MySQL/src/main/java/com/vam/controller/AdminController.java +++ b/VamPa_MySQL/src/main/java/com/vam/controller/AdminController.java @@ -1,5 +1,8 @@ package com.vam.controller; +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.List; import org.slf4j.Logger; @@ -11,6 +14,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.mvc.support.RedirectAttributes; import com.fasterxml.jackson.core.JsonProcessingException; @@ -263,6 +267,39 @@ public class AdminController { model.addAttribute("pageMaker", new PageDTO(cri, authorService.authorGetTotal(cri))); } - + /* 첨부 파일 업로드 */ + @PostMapping("/uploadAjaxAction") + public void uploadAjaxActionPOST(MultipartFile[] uploadFile) { + + logger.info("uploadAjaxActionPOST.........."); + String uploadFolder = "C:\\upload"; + + /* 날짜 폴더 경로 */ + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + + Date date = new Date(); + + String str = sdf.format(date); + + String datePath = str.replace("-", File.separator); + + /* 폴더 생성 */ + File uploadPath = new File(uploadFolder, datePath); + + if(uploadPath.exists() == false) { + uploadPath.mkdirs(); + } + + + + // 향상된 for + for(MultipartFile multipartFile : uploadFile) { + + } + + + + + } } diff --git a/VamPa_MySQL/src/main/webapp/WEB-INF/views/admin/goodsEnroll.jsp b/VamPa_MySQL/src/main/webapp/WEB-INF/views/admin/goodsEnroll.jsp index f8d64e7..562774f 100644 --- a/VamPa_MySQL/src/main/webapp/WEB-INF/views/admin/goodsEnroll.jsp +++ b/VamPa_MySQL/src/main/webapp/WEB-INF/views/admin/goodsEnroll.jsp @@ -465,6 +465,7 @@ $("#enrollBtn").on("click",function(e){ /* 이미지 업로드 */ $("input[type='file']").on("change", function(e){ + let formData = new FormData(); let fileInput = $('input[name="uploadFile"]'); let fileList = fileInput[0].files; let fileObj = fileList[0]; @@ -473,7 +474,17 @@ $("#enrollBtn").on("click",function(e){ return false; } - alert("통과"); + formData.append("uploadFile", fileObj); + + $.ajax({ + url: '/admin/uploadAjaxAction', + processData : false, + contentType : false, + data : formData, + type : 'POST', + dataType : 'json' + }); + }); diff --git a/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties b/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties index af82c83..1d57ffa 100644 --- a/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties +++ b/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven Integration for Eclipse -#Wed Apr 28 02:05:10 KST 2021 +#Mon May 10 05:53:52 KST 2021 m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa_MySQL m2e.projectName=VamPa_MySQL groupId=com.vam