[Spring][쇼핑몰 프로젝트][24] 상품 이미지 업로드(저장 폴더 생성) - 3
https://kimvampa.tistory.com/215
This commit is contained in:
@@ -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) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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'
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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'
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user