[Spring][쇼핑몰 프로젝트][22] 상품 정보 삭제 구현

https://kimvampa.tistory.com/209
This commit is contained in:
SeoJin Kim
2021-04-26 21:04:02 +09:00
parent 28bc356fce
commit 7d33d4cfd8
22 changed files with 176 additions and 8 deletions

View File

@@ -115,6 +115,20 @@ public class AdminController {
}
/* 상품 정보 삭제 */
@PostMapping("/goodsDelete")
public String goodsDeletePOST(int bookId, RedirectAttributes rttr) {
logger.info("goodsDeletePOST..........");
int result = adminService.goodsDelete(bookId);
rttr.addFlashAttribute("delete_result", result);
return "redirect:/admin/goodsManage";
}
/* 작가 등록 페이지 접속 */
@RequestMapping(value = "authorEnroll", method = RequestMethod.GET)
public void authorEnrollGET() throws Exception{

View File

@@ -26,4 +26,7 @@ public interface AdminMapper {
/* 상품 수정 */
public int goodsModify(BookVO vo);
/* 상품 정보 삭제 */
public int goodsDelete(int bookId);
}

View File

@@ -24,6 +24,9 @@ public interface AdminService {
public BookVO goodsGetDetail(int bookId);
/* 상품 수정 */
public int goodsModify(BookVO vo);
public int goodsModify(BookVO vo);
/* 상품 정보 삭제 */
public int goodsDelete(int bookId);
}

View File

@@ -74,4 +74,13 @@ public class AdminServiceImpl implements AdminService {
}
/* 상품 정보 삭제 */
@Override
public int goodsDelete(int bookId) {
log.info("goodsDelete..........");
return adminMapper.goodsDelete(bookId);
}
}

View File

@@ -74,5 +74,12 @@
where bookId = ${bookId}
</update>
<!-- 상품 정보 삭제 -->
<delete id="goodsDelete">
delete from vam_book where bookId = #{bookId}
</delete>
</mapper>

View File

@@ -130,6 +130,13 @@ $(document).ready(function(){
if(modify_result == 1){
alert("수정 완료");
}
/* 삭제 결과 경고창 */
let delete_result = '${delete_result}';
if(delete_result == 1){
alert("삭제 완료");
}
});

View File

@@ -140,6 +140,7 @@
<div class="btn_section">
<button id="cancelBtn" class="btn">취 소</button>
<button id="modifyBtn" class="btn modify_btn">수 정</button>
<button id="deleteBtn" class="btn delete_btn">삭 제</button>
</div>
</div>
<form id="moveForm" action="/admin/goodsManage" method="get" >
@@ -429,6 +430,17 @@
$("#moveForm").submit();
});
/* 삭제 버튼 */
$("#deleteBtn").on("click", function(e){
e.preventDefault();
let moveForm = $("#moveForm");
moveForm.find("input").remove();
moveForm.append('<input type="hidden" name="bookId" value="${goodsInfo.bookId}">');
moveForm.attr("action", "/admin/goodsDelete");
moveForm.attr("method", "post");
moveForm.submit();
});
/* 수정 버튼 */
$("#modifyBtn").on("click",function(e){

View File

@@ -186,6 +186,12 @@ input[name='publeYear'] {
#enrollBtn:hover {
background-color: #c9cbd0;
}
.delete_btn{
background-color: #efcdcd;
}
.delete_btn:hover{
background-color : #e4a7a7;
}
.form_section_content select { /* 카테고리 css 설정 */
width: 92%;

View File

@@ -89,6 +89,7 @@ public class AdminMapperTests {
*/
/* 상품 정보 수정 */
/*
@Test
public void goodsModifyTest() {
@@ -109,6 +110,21 @@ public class AdminMapperTests {
mapper.goodsModify(book);
}
*/
/* 상품 정보 삭제 */
@Test
public void goodsDeleteTest() {
int bookId = 169;
int result = mapper.goodsDelete(bookId);
if(result == 1) {
System.out.println("삭제 성공");
}
}
}

View File

@@ -74,5 +74,12 @@
where bookId = ${bookId}
</update>
<!-- 상품 정보 삭제 -->
<delete id="goodsDelete">
delete from vam_book where bookId = #{bookId}
</delete>
</mapper>

View File

@@ -1,6 +1,6 @@
#Generated by Maven Integration for Eclipse
#Sun Apr 25 22:01:07 KST 2021
m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project\\VamPa
#Mon Apr 26 20:57:20 KST 2021
m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa
m2e.projectName=VamPa
groupId=com.vam
artifactId=controller

View File

@@ -115,6 +115,20 @@ public class AdminController {
}
/* 상품 정보 삭제 */
@PostMapping("/goodsDelete")
public String goodsDeletePOST(int bookId, RedirectAttributes rttr) {
logger.info("goodsDeletePOST..........");
int result = adminService.goodsDelete(bookId);
rttr.addFlashAttribute("delete_result", result);
return "redirect:/admin/goodsManage";
}
/* 작가 등록 페이지 접속 */
@RequestMapping(value = "authorEnroll", method = RequestMethod.GET)

View File

@@ -27,4 +27,7 @@ public interface AdminMapper {
/* 상품 수정 */
public int goodsModify(BookVO vo);
/* 상품 정보 삭제 */
public int goodsDelete(int bookId);
}

View File

@@ -24,6 +24,9 @@ public interface AdminService {
public BookVO goodsGetDetail(int bookId);
/* 상품 수정 */
public int goodsModify(BookVO vo);
public int goodsModify(BookVO vo);
/* 상품 정보 삭제 */
public int goodsDelete(int bookId);
}

View File

@@ -70,4 +70,13 @@ public class AdminServiceImpl implements AdminService {
}
/* 상품 정보 삭제 */
@Override
public int goodsDelete(int bookId) {
log.info("goodsDelete..........");
return adminMapper.goodsDelete(bookId);
}
}

View File

@@ -64,5 +64,12 @@
where bookId = ${bookId}
</update>
<!-- 상품 정보 삭제 -->
<delete id="goodsDelete">
delete from vam_book where bookId = #{bookId}
</delete>
</mapper>

View File

@@ -130,6 +130,13 @@ $(document).ready(function(){
if(modify_result == 1){
alert("수정 완료");
}
/* 삭제 결과 경고창 */
let delete_result = '${delete_result}';
if(delete_result == 1){
alert("삭제 완료");
}
});

View File

@@ -140,6 +140,7 @@
<div class="btn_section">
<button id="cancelBtn" class="btn">취 소</button>
<button id="modifyBtn" class="btn modify_btn">수 정</button>
<button id="deleteBtn" class="btn delete_btn">삭 제</button>
</div>
</div>
<form id="moveForm" action="/admin/goodsDetail" method="get" >
@@ -427,6 +428,17 @@
$("#moveForm").submit();
});
/* 삭제 버튼 */
$("#deleteBtn").on("click", function(e){
e.preventDefault();
let moveForm = $("#moveForm");
moveForm.find("input").remove();
moveForm.append('<input type="hidden" name="bookId" value="${goodsInfo.bookId}">');
moveForm.attr("action", "/admin/goodsDelete");
moveForm.attr("method", "post");
moveForm.submit();
});
/* 수정 버튼 */
$("#modifyBtn").on("click",function(e){

View File

@@ -186,6 +186,12 @@ input[name='publeYear'] {
#enrollBtn:hover {
background-color: #c9cbd0;
}
.delete_btn{
background-color: #efcdcd;
}
.delete_btn:hover{
background-color : #e4a7a7;
}
.form_section_content select { /* 카테고리 css 설정 */
width: 92%;

View File

@@ -91,17 +91,18 @@ public class AdminMapperTests {
*/
/* 상품 정보 수정 */
/*
@Test
public void goodsModifyTest() {
BookVO book = new BookVO();
book.setBookId(4);
book.setBookId(95);
book.setBookName("mapper 테스트");
book.setAuthorId(94);
book.setPubleYear("2021-03-18");
book.setPublisher("출판사");
book.setCateCode("104002");
book.setCateCode("103002");
book.setBookPrice(20000);
book.setBookStock(300);
book.setBookDiscount(0.23);
@@ -111,5 +112,20 @@ public class AdminMapperTests {
mapper.goodsModify(book);
}
*/
/* 상품 정보 삭제 */
@Test
public void goodsDeleteTest() {
int bookId = 169;
int result = mapper.goodsDelete(bookId);
if(result == 1) {
System.out.println("삭제 성공");
}
}
}

View File

@@ -64,5 +64,12 @@
where bookId = ${bookId}
</update>
<!-- 상품 정보 삭제 -->
<delete id="goodsDelete">
delete from vam_book where bookId = #{bookId}
</delete>
</mapper>

View File

@@ -1,6 +1,6 @@
#Generated by Maven Integration for Eclipse
#Sun Apr 25 22:01:08 KST 2021
m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project\\VamPa_MySQL
#Mon Apr 26 20:56:47 KST 2021
m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa_MySQL
m2e.projectName=VamPa_MySQL
groupId=com.vam
artifactId=controller