[Spring][쇼핑몰 프로젝트][27] 업로드 이미지 정보 등록 - 4
https://kimvampa.tistory.com/230?category=771727
This commit is contained in:
@@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.vam.mapper.AdminMapper;
|
||||
import com.vam.model.AttachImageVO;
|
||||
import com.vam.model.BookVO;
|
||||
import com.vam.model.CateVO;
|
||||
import com.vam.model.Criteria;
|
||||
@@ -27,6 +28,18 @@ public class AdminServiceImpl implements AdminService {
|
||||
|
||||
adminMapper.bookEnroll(book);
|
||||
|
||||
if(book.getImageList() == null || book.getImageList().size() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
book.getImageList().forEach(attach ->{
|
||||
|
||||
attach.setBookId(book.getBookId());
|
||||
adminMapper.imageEnroll(attach);
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* 카테고리 리스트 */
|
||||
|
||||
68
VamPa/src/test/java/com/vam/service/AdminServiceTests.java
Normal file
68
VamPa/src/test/java/com/vam/service/AdminServiceTests.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package com.vam.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.vam.model.AttachImageVO;
|
||||
import com.vam.model.BookVO;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("file:src/main/webapp/WEB-INF/spring/root-context.xml")
|
||||
public class AdminServiceTests {
|
||||
|
||||
@Autowired
|
||||
private AdminService service;
|
||||
|
||||
|
||||
/* 상품 등록 & 상품 이미지 등록 테스트 */
|
||||
@Test
|
||||
public void bookEnrollTEsts() {
|
||||
|
||||
BookVO book = new BookVO();
|
||||
// 상품 정보
|
||||
book.setBookName("service 테스트");
|
||||
book.setAuthorId(27);
|
||||
book.setPubleYear("2021-03-18");
|
||||
book.setPublisher("출판사");
|
||||
book.setCateCode("202001");
|
||||
book.setBookPrice(20000);
|
||||
book.setBookStock(300);
|
||||
book.setBookDiscount(0.23);
|
||||
book.setBookIntro("책 소개 ");
|
||||
book.setBookContents("책 목차 ");
|
||||
|
||||
// 이미지 정보
|
||||
List<AttachImageVO> imageList = new ArrayList<AttachImageVO>();
|
||||
|
||||
AttachImageVO image1 = new AttachImageVO();
|
||||
AttachImageVO image2 = new AttachImageVO();
|
||||
|
||||
image1.setFileName("test Image 1");
|
||||
image1.setUploadPath("test image 1");
|
||||
image1.setUuid("test1111");
|
||||
|
||||
image2.setFileName("test Image 2");
|
||||
image2.setUploadPath("test image 2");
|
||||
image2.setUuid("test2222");
|
||||
|
||||
imageList.add(image1);
|
||||
imageList.add(image2);
|
||||
|
||||
|
||||
book.setImageList(imageList);
|
||||
|
||||
// bookEnroll() 메서드 호출
|
||||
service.bookEnroll(book);
|
||||
|
||||
System.out.println("등록된 VO : " + book);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
#Generated by Maven Integration for Eclipse
|
||||
#Mon Jun 07 20:30:56 KST 2021
|
||||
#Sun Jun 13 17:29:35 KST 2021
|
||||
m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa
|
||||
m2e.projectName=VamPa
|
||||
groupId=com.vam
|
||||
|
||||
@@ -27,6 +27,18 @@ public class AdminServiceImpl implements AdminService {
|
||||
|
||||
adminMapper.bookEnroll(book);
|
||||
|
||||
if(book.getImageList() == null || book.getImageList().size() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
book.getImageList().forEach(attach ->{
|
||||
|
||||
attach.setBookId(book.getBookId());
|
||||
adminMapper.imageEnroll(attach);
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* 카테고리 리스트 */
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.vam.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.vam.model.AttachImageVO;
|
||||
import com.vam.model.BookVO;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("file:src/main/webapp/WEB-INF/spring/root-context.xml")
|
||||
public class AdminServiceTests {
|
||||
|
||||
@Autowired
|
||||
private AdminService service;
|
||||
|
||||
|
||||
/* 상품 등록 & 상품 이미지 등록 테스트 */
|
||||
@Test
|
||||
public void bookEnrollTEsts() {
|
||||
|
||||
BookVO book = new BookVO();
|
||||
// 상품 정보
|
||||
book.setBookName("mapper 테스트");
|
||||
book.setAuthorId(8);
|
||||
book.setPubleYear("2021-03-18");
|
||||
book.setPublisher("출판사");
|
||||
book.setCateCode("202001");
|
||||
book.setBookPrice(20000);
|
||||
book.setBookStock(300);
|
||||
book.setBookDiscount(0.23);
|
||||
book.setBookIntro("책 소개 ");
|
||||
book.setBookContents("책 목차 ");
|
||||
|
||||
// 이미지 정보
|
||||
List<AttachImageVO> imageList = new ArrayList<AttachImageVO>();
|
||||
|
||||
AttachImageVO image1 = new AttachImageVO();
|
||||
AttachImageVO image2 = new AttachImageVO();
|
||||
|
||||
image1.setFileName("test Image 1");
|
||||
image1.setUploadPath("test image 1");
|
||||
image1.setUuid("test1111");
|
||||
|
||||
image2.setFileName("test Image 2");
|
||||
image2.setUploadPath("test image 2");
|
||||
image2.setUuid("test2222");
|
||||
|
||||
imageList.add(image1);
|
||||
imageList.add(image2);
|
||||
|
||||
|
||||
book.setImageList(imageList);
|
||||
|
||||
// bookEnroll() 메서드 호출
|
||||
service.bookEnroll(book);
|
||||
|
||||
System.out.println("등록된 VO : " + book);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
#Generated by Maven Integration for Eclipse
|
||||
#Mon Jun 07 20:30:56 KST 2021
|
||||
#Sun Jun 13 18:53:10 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