[Spring][쇼핑몰 프로젝트][14] 작가등록 기능 구현 -2

https://kimvampa.tistory.com/156
This commit is contained in:
SeoJin Kim
2021-02-09 18:41:41 +09:00
parent b0e5639227
commit f6dfa4058e
7 changed files with 220 additions and 1 deletions

View File

@@ -2,9 +2,14 @@ package com.vam.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.vam.model.AuthorVO;
import com.vam.service.AuthorService;
@Controller
@RequestMapping("/admin")
@@ -12,6 +17,9 @@ public class AdminController {
private static final Logger logger = LoggerFactory.getLogger(AdminController.class);
@Autowired
private AuthorService authorService;
/* 관리자 메인 페이지 이동 */
@RequestMapping(value="main", method = RequestMethod.GET)
public void adminMainGET() throws Exception{
@@ -44,6 +52,19 @@ public class AdminController {
logger.info("작가 관리 페이지 접속");
}
/* 작가 등록 */
@RequestMapping(value="authorEnroll.do", method = RequestMethod.POST)
public String authorEnrollPOST(AuthorVO author, RedirectAttributes rttr) throws Exception{
logger.info("authorEnroll :" + author);
authorService.authorEnroll(author); // 작가 등록 쿼리 수행
rttr.addFlashAttribute("enroll_result", author.getAuthorName()); // 등록 성공 메시지(작가이름)
return "redirect:/admin/authorManage";
}
}

View File

@@ -54,6 +54,42 @@
</div>
<div class="admin_content_wrap">
<div class="admin_content_subject"><span>작가 등록</span></div>
<div class="admin_content_main">
<form action="/admin/authorEnroll.do" method="post" id="enrollForm">
<div class="form_section">
<div class="form_section_title">
<label>작가 이름</label>
</div>
<div class="form_section_content">
<input name="authorName">
</div>
</div>
<div class="form_section">
<div class="form_section_title">
<label>소속 국가</label>
</div>
<div class="form_section_content">
<select name="nationId">
<option value="none" selected>=== 선택 ===</option>
<option value="01">국내</option>
<option value="02">국외</option>
</select>
</div>
</div>
<div class="form_section">
<div class="form_section_title">
<label>작가소개</label>
</div>
<div class="form_section_content">
<input name="authorIntro" type="text">
</div>
</div>
</form>
<div class="btn_section">
<button id="cancelBtn" class="btn">취 소</button>
<button id="enrollBtn" class="btn enroll_btn">등 록</button>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
@@ -99,5 +135,19 @@
</div> <!-- class="wrap" -->
</div> <!-- class="wrapper" -->
<script>
/* 등록 버튼 */
$("#enrollBtn").click(function(){
$("#enrollForm").submit();
});
/* 취소 버튼 */
$("#cancelBtn").click(function(){
location.href="/admin/authorManage"
});
</script>
</body>
</html>

View File

@@ -1,5 +1,6 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
@@ -99,5 +100,25 @@
</div> <!-- class="wrap" -->
</div> <!-- class="wrapper" -->
<script>
$(document).ready(function(){
let result = '<c:out value="${enroll_result}"/>';
checkResult(result);
function checkResult(result){
if(result === ''){
return;
}
alert("작가'${enroll_result}'을 등록하였습니다.");
}
});
</script>
</body>
</html>

View File

@@ -0,0 +1,32 @@
package com.vam.service;
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.AuthorVO;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("file:src/main/webapp/WEB-INF/spring/root-context.xml")
public class AuthorServiceTests {
/*AuthoreService 의존성 주입*/
@Autowired
private AuthorService service;
@Test
public void authorEnrollTest() throws Exception {
AuthorVO author = new AuthorVO();
author.setNationId("01");
author.setAuthorName("테스트");
author.setAuthorIntro("테스트 소개");
service.authorEnroll(author);
}
}

View File

@@ -2,9 +2,14 @@ package com.vam.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.vam.model.AuthorVO;
import com.vam.service.AuthorService;
@Controller
@RequestMapping("/admin")
@@ -12,6 +17,10 @@ public class AdminController {
private static final Logger logger = LoggerFactory.getLogger(AdminController.class);
@Autowired
private AuthorService authorService;
/* 관리자 메인 페이지 이동 */
@RequestMapping(value="main", method = RequestMethod.GET)
public void adminMainGET() throws Exception{
@@ -43,5 +52,20 @@ public class AdminController {
public void authorManageGET() throws Exception{
logger.info("작가 관리 페이지 접속");
}
/* 작가 등록 */
@RequestMapping(value="authorEnroll.do", method = RequestMethod.POST)
public String authorEnrollPOST(AuthorVO author, RedirectAttributes rttr) throws Exception{
logger.info("authorEnroll :" + author);
authorService.authorEnroll(author); // 작가 등록 쿼리 수행
rttr.addFlashAttribute("enroll_result", author.getAuthorName()); // 등록 성공 메시지(작가이름)
return "redirect:/admin/authorManage";
}
}

View File

@@ -54,6 +54,42 @@
</div>
<div class="admin_content_wrap">
<div class="admin_content_subject"><span>작가 등록</span></div>
<div class="admin_content_main">
<form action="/admin/authorEnroll.do" method="post" id="enrollForm">
<div class="form_section">
<div class="form_section_title">
<label>작가 이름</label>
</div>
<div class="form_section_content">
<input name="authorName">
</div>
</div>
<div class="form_section">
<div class="form_section_title">
<label>소속 국가</label>
</div>
<div class="form_section_content">
<select name="nationId">
<option value="none" selected>=== 선택 ===</option>
<option value="01">국내</option>
<option value="02">국외</option>
</select>
</div>
</div>
<div class="form_section">
<div class="form_section_title">
<label>작가소개</label>
</div>
<div class="form_section_content">
<input name="authorIntro" type="text">
</div>
</div>
</form>
<div class="btn_section">
<button id="cancelBtn" class="btn">취 소</button>
<button id="enrollBtn" class="btn enroll_btn">등 록</button>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
@@ -99,5 +135,19 @@
</div> <!-- class="wrap" -->
</div> <!-- class="wrapper" -->
<script>
/* 등록 버튼 */
$("#enrollBtn").click(function(){
$("#enrollForm").submit();
});
/* 취소 버튼 */
$("#cancelBtn").click(function(){
location.href="/admin/authorManage"
});
</script>
</body>
</html>

View File

@@ -1,5 +1,6 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
@@ -99,5 +100,25 @@
</div> <!-- class="wrap" -->
</div> <!-- class="wrapper" -->
<script>
$(document).ready(function(){
let result = '<c:out value="${enroll_result}"/>';
checkResult(result);
function checkResult(result){
if(result === ''){
return;
}
alert("작가'${enroll_result}'을 등록하였습니다.");
}
});
</script>
</body>
</html>