[Spring][쇼핑몰 프로젝트][23] 작가 정보 삭제 구현

https://kimvampa.tistory.com/210
This commit is contained in:
SeoJin Kim
2021-04-26 22:54:14 +09:00
parent 7d33d4cfd8
commit 12175865c4
23 changed files with 205 additions and 6 deletions

View File

@@ -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) {

View File

@@ -22,4 +22,7 @@ public interface AuthorMapper {
/* 작가 정보 수정 */
public int authorModify(AuthorVO author);
/* 작가 정보 삭제 */
public int authorDelete(int authorId);
}

View File

@@ -22,4 +22,7 @@ public interface AuthorService {
/* 작가 정보 수정 */
public int authorModify(AuthorVO author) throws Exception;
/* 작가 정보 삭제 */
public int authorDelete(int authorId);
}

View File

@@ -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);
}
}

View File

@@ -62,4 +62,11 @@
</update>
<!-- 작가 정보 삭제 -->
<delete id="authorDelete">
delete from vam_author where authorId = #{authorId}
</delete>
</mapper>

View File

@@ -140,6 +140,15 @@ $(document).ready(function(){
}
/* 삭제 결과 경고창 */
let delete_result = '${delete_result}';
if(delete_result == 1){
alert("삭제 완료");
} else if(delete_result == 2){
alert("해당 작가 데이터를 사용하고 있는 데이터가 있어서 삭제 할 수 없습니다.")
}
});

View File

@@ -77,6 +77,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>
</form>
</div>
@@ -108,6 +109,16 @@
});
/* 삭제 버튼 */
$("#deleteBtn").on("click", function(e){
e.preventDefault();
moveForm.find("input").remove();
moveForm.append('<input type="hidden" name="authorId" value="${authorInfo.authorId}">');
moveForm.attr("action", "/admin/authorDelete");
moveForm.attr("method", "post");
moveForm.submit();
});
/* 작가 수정 버튼 작동 및 유효성 검사 */
$("#modifyBtn").on("click", function(e){

View File

@@ -176,7 +176,12 @@ ul{
background-color: #b8d3e8;
margin-left:15px;
}
.delete_btn{
background-color: #efcdcd;
}
.delete_btn:hover{
background-color : #e4a7a7;
}

View File

@@ -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("삭제 성공");
}
}
}

View File

@@ -62,4 +62,11 @@
</update>
<!-- 작가 정보 삭제 -->
<delete id="authorDelete">
delete from vam_author where authorId = #{authorId}
</delete>
</mapper>

View File

@@ -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

View File

@@ -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")

View File

@@ -21,5 +21,8 @@ public interface AuthorMapper {
/* 작가 정보 수정 */
public int authorModify(AuthorVO author);
/* 작가 정보 삭제 */
public int authorDelete(int authorId);
}

View File

@@ -22,4 +22,7 @@ public interface AuthorService {
/* 작가 정보 수정 */
public int authorModify(AuthorVO author) throws Exception;
/* 작가 정보 삭제 */
public int authorDelete(int authorId);
}

View File

@@ -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);
}
}

View File

@@ -51,6 +51,13 @@
update vam_author set authorName=#{authorName}, nationId=#{nationId}, authorIntro=#{authorIntro}, updatedate=now() where authorId = #{authorId}
</update>
<!-- 작가 정보 삭제 -->
<delete id="authorDelete">
delete from vam_author where authorId = #{authorId}
</delete>
</mapper>

View File

@@ -140,6 +140,15 @@ $(document).ready(function(){
}
/* 삭제 결과 경고창 */
let delete_result = '${delete_result}';
if(delete_result == 1){
alert("삭제 완료");
} else if(delete_result == 2){
alert("해당 작가 데이터를 사용하고 있는 데이터가 있어서 삭제 할 수 없습니다.")
}
});

View File

@@ -77,6 +77,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>
</form>
</div>
@@ -108,6 +109,16 @@
});
/* 삭제 버튼 */
$("#deleteBtn").on("click", function(e){
e.preventDefault();
moveForm.find("input").remove();
moveForm.append('<input type="hidden" name="authorId" value="${authorInfo.authorId}">');
moveForm.attr("action", "/admin/authorDelete");
moveForm.attr("method", "post");
moveForm.submit();
});
/* 작가 수정 버튼 작동 및 유효성 검사 */
$("#modifyBtn").on("click", function(e){

View File

@@ -176,7 +176,12 @@ ul{
background-color: #b8d3e8;
margin-left:15px;
}
.delete_btn{
background-color: #efcdcd;
}
.delete_btn:hover{
background-color : #e4a7a7;
}

View File

@@ -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("삭제 성공");
}
}
}

View File

@@ -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")

View File

@@ -51,6 +51,13 @@
update vam_author set authorName=#{authorName}, nationId=#{nationId}, authorIntro=#{authorIntro}, updatedate=now() where authorId = #{authorId}
</update>
<!-- 작가 정보 삭제 -->
<delete id="authorDelete">
delete from vam_author where authorId = #{authorId}
</delete>
</mapper>

View File

@@ -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