From 12175865c4caeb4ce7ec5784e5fad481fc20ea2a Mon Sep 17 00:00:00 2001 From: SeoJin Kim Date: Mon, 26 Apr 2021 22:54:14 +0900 Subject: [PATCH] =?UTF-8?q?[Spring][=EC=87=BC=ED=95=91=EB=AA=B0=20?= =?UTF-8?q?=ED=94=84=EB=A1=9C=EC=A0=9D=ED=8A=B8][23]=20=EC=9E=91=EA=B0=80?= =?UTF-8?q?=20=EC=A0=95=EB=B3=B4=20=EC=82=AD=EC=A0=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://kimvampa.tistory.com/210 --- .../com/vam/controller/AdminController.java | 29 +++++++++++++++++++ .../java/com/vam/mapper/AuthorMapper.java | 3 ++ .../java/com/vam/service/AuthorService.java | 3 ++ .../com/vam/service/AuthorServiceImpl.java | 11 ++++++- .../resources/com/vam/mapper/AuthorMapper.xml | 7 +++++ .../WEB-INF/views/admin/authorManage.jsp | 9 ++++++ .../WEB-INF/views/admin/authorModify.jsp | 11 +++++++ .../resources/css/admin/authorModify.css | 7 ++++- .../com/vam/mapper/AuthorMapperTests.java | 16 ++++++++++ .../classes/com/vam/mapper/AuthorMapper.xml | 7 +++++ .../maven/com.vam/controller/pom.properties | 2 +- .../com/vam/controller/AdminController.java | 29 +++++++++++++++++++ .../java/com/vam/mapper/AuthorMapper.java | 3 ++ .../java/com/vam/service/AuthorService.java | 3 ++ .../com/vam/service/AuthorServiceImpl.java | 9 ++++++ .../resources/com/vam/mapper/AuthorMapper.xml | 7 +++++ .../WEB-INF/views/admin/authorManage.jsp | 9 ++++++ .../WEB-INF/views/admin/authorModify.jsp | 11 +++++++ .../resources/css/admin/authorModify.css | 7 ++++- .../com/vam/mapper/AuthorMapperTests.java | 17 +++++++++++ .../com/vam/service/AuthorServiceTests.java | 2 +- .../classes/com/vam/mapper/AuthorMapper.xml | 7 +++++ .../maven/com.vam/controller/pom.properties | 2 +- 23 files changed, 205 insertions(+), 6 deletions(-) diff --git a/VamPa/src/main/java/com/vam/controller/AdminController.java b/VamPa/src/main/java/com/vam/controller/AdminController.java index 8a89537..08f5632 100644 --- a/VamPa/src/main/java/com/vam/controller/AdminController.java +++ b/VamPa/src/main/java/com/vam/controller/AdminController.java @@ -197,6 +197,35 @@ public class AdminController { } + /* 작가 정보 삭제 */ + @PostMapping("/authorDelete") + public String authorDeletePOST(int authorId, RedirectAttributes rttr) { + + logger.info("authorDeletePOST.........."); + + int result = 0; + + try { + + result = authorService.authorDelete(authorId); + + } catch (Exception e) { + + e.printStackTrace(); + result = 2; + rttr.addFlashAttribute("delete_result", result); + + return "redirect:/admin/authorManage"; + + } + + + rttr.addFlashAttribute("delete_result", result); + + return "redirect:/admin/authorManage"; + + } + /* 상품 등록 */ @PostMapping("/goodsEnroll") public String goodsEnrollPOST(BookVO book, RedirectAttributes rttr) { diff --git a/VamPa/src/main/java/com/vam/mapper/AuthorMapper.java b/VamPa/src/main/java/com/vam/mapper/AuthorMapper.java index cda6633..edc2210 100644 --- a/VamPa/src/main/java/com/vam/mapper/AuthorMapper.java +++ b/VamPa/src/main/java/com/vam/mapper/AuthorMapper.java @@ -22,4 +22,7 @@ public interface AuthorMapper { /* 작가 정보 수정 */ public int authorModify(AuthorVO author); + /* 작가 정보 삭제 */ + public int authorDelete(int authorId); + } diff --git a/VamPa/src/main/java/com/vam/service/AuthorService.java b/VamPa/src/main/java/com/vam/service/AuthorService.java index ce8fdf6..b178a8d 100644 --- a/VamPa/src/main/java/com/vam/service/AuthorService.java +++ b/VamPa/src/main/java/com/vam/service/AuthorService.java @@ -22,4 +22,7 @@ public interface AuthorService { /* 작가 정보 수정 */ public int authorModify(AuthorVO author) throws Exception; + /* 작가 정보 삭제 */ + public int authorDelete(int authorId); + } diff --git a/VamPa/src/main/java/com/vam/service/AuthorServiceImpl.java b/VamPa/src/main/java/com/vam/service/AuthorServiceImpl.java index 307f50c..43b1045 100644 --- a/VamPa/src/main/java/com/vam/service/AuthorServiceImpl.java +++ b/VamPa/src/main/java/com/vam/service/AuthorServiceImpl.java @@ -55,6 +55,15 @@ public class AuthorServiceImpl implements AuthorService { public int authorModify(AuthorVO author) throws Exception { log.info("(service) authorModify........." + author); return authorMapper.authorModify(author); - } + } + + /* 작가 정보 삭제 */ + @Override + public int authorDelete(int authorId) { + + log.info("authorDelete.........."); + + return authorMapper.authorDelete(authorId); + } } diff --git a/VamPa/src/main/resources/com/vam/mapper/AuthorMapper.xml b/VamPa/src/main/resources/com/vam/mapper/AuthorMapper.xml index ad6dd8c..17e8ef3 100644 --- a/VamPa/src/main/resources/com/vam/mapper/AuthorMapper.xml +++ b/VamPa/src/main/resources/com/vam/mapper/AuthorMapper.xml @@ -62,4 +62,11 @@ + + + + delete from vam_author where authorId = #{authorId} + + + \ No newline at end of file diff --git a/VamPa/src/main/webapp/WEB-INF/views/admin/authorManage.jsp b/VamPa/src/main/webapp/WEB-INF/views/admin/authorManage.jsp index c76cada..5a244b6 100644 --- a/VamPa/src/main/webapp/WEB-INF/views/admin/authorManage.jsp +++ b/VamPa/src/main/webapp/WEB-INF/views/admin/authorManage.jsp @@ -140,6 +140,15 @@ $(document).ready(function(){ } + /* 삭제 결과 경고창 */ + let delete_result = '${delete_result}'; + + if(delete_result == 1){ + alert("삭제 완료"); + } else if(delete_result == 2){ + alert("해당 작가 데이터를 사용하고 있는 데이터가 있어서 삭제 할 수 없습니다.") + } + }); diff --git a/VamPa/src/main/webapp/WEB-INF/views/admin/authorModify.jsp b/VamPa/src/main/webapp/WEB-INF/views/admin/authorModify.jsp index c09e599..5a46423 100644 --- a/VamPa/src/main/webapp/WEB-INF/views/admin/authorModify.jsp +++ b/VamPa/src/main/webapp/WEB-INF/views/admin/authorModify.jsp @@ -77,6 +77,7 @@
+
@@ -108,6 +109,16 @@ }); + /* 삭제 버튼 */ + $("#deleteBtn").on("click", function(e){ + e.preventDefault(); + moveForm.find("input").remove(); + moveForm.append(''); + moveForm.attr("action", "/admin/authorDelete"); + moveForm.attr("method", "post"); + moveForm.submit(); + }); + /* 작가 수정 버튼 작동 및 유효성 검사 */ $("#modifyBtn").on("click", function(e){ diff --git a/VamPa/src/main/webapp/resources/css/admin/authorModify.css b/VamPa/src/main/webapp/resources/css/admin/authorModify.css index fe5d746..c9f974e 100644 --- a/VamPa/src/main/webapp/resources/css/admin/authorModify.css +++ b/VamPa/src/main/webapp/resources/css/admin/authorModify.css @@ -176,7 +176,12 @@ ul{ background-color: #b8d3e8; margin-left:15px; } - +.delete_btn{ + background-color: #efcdcd; +} +.delete_btn:hover{ + background-color : #e4a7a7; +} diff --git a/VamPa/src/test/java/com/vam/mapper/AuthorMapperTests.java b/VamPa/src/test/java/com/vam/mapper/AuthorMapperTests.java index c344cca..d63bb1a 100644 --- a/VamPa/src/test/java/com/vam/mapper/AuthorMapperTests.java +++ b/VamPa/src/test/java/com/vam/mapper/AuthorMapperTests.java @@ -82,6 +82,7 @@ public class AuthorMapperTests { */ /* 작가 정보 수정 */ + /* @Test public void authorModifyTest() { @@ -98,7 +99,22 @@ public class AuthorMapperTests { System.out.println("수정 후...................." + mapper.authorGetDetail(author.getAuthorId())); } + */ + /* 작가 정보 삭제 */ + @Test + public void authorDeleteTest() { + + + int authorId = 13; + + int result = mapper.authorDelete(authorId); + + if(result == 1) { + System.out.println("삭제 성공"); + } + + } } diff --git a/VamPa/target/classes/com/vam/mapper/AuthorMapper.xml b/VamPa/target/classes/com/vam/mapper/AuthorMapper.xml index ad6dd8c..17e8ef3 100644 --- a/VamPa/target/classes/com/vam/mapper/AuthorMapper.xml +++ b/VamPa/target/classes/com/vam/mapper/AuthorMapper.xml @@ -62,4 +62,11 @@ + + + + delete from vam_author where authorId = #{authorId} + + + \ No newline at end of file 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 d3e81b1..c9e83ba 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 -#Mon Apr 26 20:57:20 KST 2021 +#Mon Apr 26 22:35:37 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 c134e32..1f8ae24 100644 --- a/VamPa_MySQL/src/main/java/com/vam/controller/AdminController.java +++ b/VamPa_MySQL/src/main/java/com/vam/controller/AdminController.java @@ -197,6 +197,35 @@ public class AdminController { return "redirect:/admin/authorManage"; } + + /* 작가 정보 삭제 */ + @PostMapping("/authorDelete") + public String authorDeletePOST(int authorId, RedirectAttributes rttr) { + + logger.info("authorDeletePOST.........."); + + int result = 0; + + try { + + result = authorService.authorDelete(authorId); + + } catch (Exception e) { + + e.printStackTrace(); + result = 2; + rttr.addFlashAttribute("delete_result", result); + + return "redirect:/admin/authorManage"; + + } + + + rttr.addFlashAttribute("delete_result", result); + + return "redirect:/admin/authorManage"; + + } /* 상품 등록 */ @PostMapping("/goodsEnroll") diff --git a/VamPa_MySQL/src/main/java/com/vam/mapper/AuthorMapper.java b/VamPa_MySQL/src/main/java/com/vam/mapper/AuthorMapper.java index 1f2319d..3aa74bf 100644 --- a/VamPa_MySQL/src/main/java/com/vam/mapper/AuthorMapper.java +++ b/VamPa_MySQL/src/main/java/com/vam/mapper/AuthorMapper.java @@ -21,5 +21,8 @@ public interface AuthorMapper { /* 작가 정보 수정 */ public int authorModify(AuthorVO author); + + /* 작가 정보 삭제 */ + public int authorDelete(int authorId); } diff --git a/VamPa_MySQL/src/main/java/com/vam/service/AuthorService.java b/VamPa_MySQL/src/main/java/com/vam/service/AuthorService.java index 9f697a8..3a7c4d9 100644 --- a/VamPa_MySQL/src/main/java/com/vam/service/AuthorService.java +++ b/VamPa_MySQL/src/main/java/com/vam/service/AuthorService.java @@ -22,4 +22,7 @@ public interface AuthorService { /* 작가 정보 수정 */ public int authorModify(AuthorVO author) throws Exception; + /* 작가 정보 삭제 */ + public int authorDelete(int authorId); + } diff --git a/VamPa_MySQL/src/main/java/com/vam/service/AuthorServiceImpl.java b/VamPa_MySQL/src/main/java/com/vam/service/AuthorServiceImpl.java index 22e206c..6091598 100644 --- a/VamPa_MySQL/src/main/java/com/vam/service/AuthorServiceImpl.java +++ b/VamPa_MySQL/src/main/java/com/vam/service/AuthorServiceImpl.java @@ -57,4 +57,13 @@ public class AuthorServiceImpl implements AuthorService { return authorMapper.authorModify(author); } + /* 작가 정보 삭제 */ + @Override + public int authorDelete(int authorId) { + + log.info("authorDelete.........."); + + return authorMapper.authorDelete(authorId); + } + } diff --git a/VamPa_MySQL/src/main/resources/com/vam/mapper/AuthorMapper.xml b/VamPa_MySQL/src/main/resources/com/vam/mapper/AuthorMapper.xml index d1dae07..df6b05a 100644 --- a/VamPa_MySQL/src/main/resources/com/vam/mapper/AuthorMapper.xml +++ b/VamPa_MySQL/src/main/resources/com/vam/mapper/AuthorMapper.xml @@ -51,6 +51,13 @@ update vam_author set authorName=#{authorName}, nationId=#{nationId}, authorIntro=#{authorIntro}, updatedate=now() where authorId = #{authorId} + + + + + delete from vam_author where authorId = #{authorId} + + \ No newline at end of file diff --git a/VamPa_MySQL/src/main/webapp/WEB-INF/views/admin/authorManage.jsp b/VamPa_MySQL/src/main/webapp/WEB-INF/views/admin/authorManage.jsp index c76cada..5a244b6 100644 --- a/VamPa_MySQL/src/main/webapp/WEB-INF/views/admin/authorManage.jsp +++ b/VamPa_MySQL/src/main/webapp/WEB-INF/views/admin/authorManage.jsp @@ -140,6 +140,15 @@ $(document).ready(function(){ } + /* 삭제 결과 경고창 */ + let delete_result = '${delete_result}'; + + if(delete_result == 1){ + alert("삭제 완료"); + } else if(delete_result == 2){ + alert("해당 작가 데이터를 사용하고 있는 데이터가 있어서 삭제 할 수 없습니다.") + } + }); diff --git a/VamPa_MySQL/src/main/webapp/WEB-INF/views/admin/authorModify.jsp b/VamPa_MySQL/src/main/webapp/WEB-INF/views/admin/authorModify.jsp index c09e599..5a46423 100644 --- a/VamPa_MySQL/src/main/webapp/WEB-INF/views/admin/authorModify.jsp +++ b/VamPa_MySQL/src/main/webapp/WEB-INF/views/admin/authorModify.jsp @@ -77,6 +77,7 @@
+
@@ -108,6 +109,16 @@ }); + /* 삭제 버튼 */ + $("#deleteBtn").on("click", function(e){ + e.preventDefault(); + moveForm.find("input").remove(); + moveForm.append(''); + moveForm.attr("action", "/admin/authorDelete"); + moveForm.attr("method", "post"); + moveForm.submit(); + }); + /* 작가 수정 버튼 작동 및 유효성 검사 */ $("#modifyBtn").on("click", function(e){ diff --git a/VamPa_MySQL/src/main/webapp/resources/css/admin/authorModify.css b/VamPa_MySQL/src/main/webapp/resources/css/admin/authorModify.css index fe5d746..c9f974e 100644 --- a/VamPa_MySQL/src/main/webapp/resources/css/admin/authorModify.css +++ b/VamPa_MySQL/src/main/webapp/resources/css/admin/authorModify.css @@ -176,7 +176,12 @@ ul{ background-color: #b8d3e8; margin-left:15px; } - +.delete_btn{ + background-color: #efcdcd; +} +.delete_btn:hover{ + background-color : #e4a7a7; +} diff --git a/VamPa_MySQL/src/test/java/com/vam/mapper/AuthorMapperTests.java b/VamPa_MySQL/src/test/java/com/vam/mapper/AuthorMapperTests.java index 084755c..1b27a5a 100644 --- a/VamPa_MySQL/src/test/java/com/vam/mapper/AuthorMapperTests.java +++ b/VamPa_MySQL/src/test/java/com/vam/mapper/AuthorMapperTests.java @@ -82,6 +82,7 @@ public class AuthorMapperTests { */ /* 작가 정보 수정 */ + /* @Test public void authorModifyTest() { @@ -98,6 +99,22 @@ public class AuthorMapperTests { System.out.println("수정 후...................." + mapper.authorGetDetail(author.getAuthorId())); } + */ + + /* 작가 정보 삭제 */ + @Test + public void authorDeleteTest() { + + + int authorId = 11; + + int result = mapper.authorDelete(authorId); + + if(result == 1) { + System.out.println("삭제 성공"); + } + + } } diff --git a/VamPa_MySQL/src/test/java/com/vam/service/AuthorServiceTests.java b/VamPa_MySQL/src/test/java/com/vam/service/AuthorServiceTests.java index 0b1a8cb..adcd6e0 100644 --- a/VamPa_MySQL/src/test/java/com/vam/service/AuthorServiceTests.java +++ b/VamPa_MySQL/src/test/java/com/vam/service/AuthorServiceTests.java @@ -11,7 +11,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.vam.model.AuthorVO; import com.vam.model.Criteria; -import jdk.internal.org.jline.utils.Log; + @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("file:src/main/webapp/WEB-INF/spring/root-context.xml") diff --git a/VamPa_MySQL/target/classes/com/vam/mapper/AuthorMapper.xml b/VamPa_MySQL/target/classes/com/vam/mapper/AuthorMapper.xml index d1dae07..df6b05a 100644 --- a/VamPa_MySQL/target/classes/com/vam/mapper/AuthorMapper.xml +++ b/VamPa_MySQL/target/classes/com/vam/mapper/AuthorMapper.xml @@ -51,6 +51,13 @@ update vam_author set authorName=#{authorName}, nationId=#{nationId}, authorIntro=#{authorIntro}, updatedate=now() where authorId = #{authorId} + + + + + delete from vam_author where authorId = #{authorId} + + \ No newline at end of file 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 117d06f..ac269e9 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 -#Mon Apr 26 20:56:47 KST 2021 +#Mon Apr 26 22:35:57 KST 2021 m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa_MySQL m2e.projectName=VamPa_MySQL groupId=com.vam