[Spring][쇼핑몰 프로젝트][15] 작가목록 기능 구현 - 2
https://kimvampa.tistory.com/184?category=771727
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
package com.vam.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
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.model.Criteria;
|
||||
import com.vam.service.AuthorService;
|
||||
|
||||
@Controller
|
||||
@@ -48,8 +52,15 @@ public class AdminController {
|
||||
|
||||
/* 작가 관리 페이지 접속 */
|
||||
@RequestMapping(value = "authorManage", method = RequestMethod.GET)
|
||||
public void authorManageGET() throws Exception{
|
||||
logger.info("작가 관리 페이지 접속");
|
||||
public void authorManageGET(Criteria cri, Model model) throws Exception{
|
||||
|
||||
logger.info("작가 관리 페이지 접속.........." + cri);
|
||||
|
||||
/* 작가 목록 출력 데이터 */
|
||||
List list = authorService.authorGetList(cri);
|
||||
|
||||
model.addAttribute("list", list);
|
||||
|
||||
}
|
||||
|
||||
/* 작가 등록 */
|
||||
|
||||
@@ -47,6 +47,11 @@ public class AuthorVO {
|
||||
|
||||
public void setNationId(String nationId) {
|
||||
this.nationId = nationId;
|
||||
if(nationId.equals("01")) {
|
||||
this.nationName = "국내";
|
||||
} else {
|
||||
this.nationName = "국외";
|
||||
}
|
||||
}
|
||||
|
||||
public String getNationName() {
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
package com.vam.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.vam.model.AuthorVO;
|
||||
import com.vam.model.Criteria;
|
||||
|
||||
public interface AuthorService {
|
||||
|
||||
/* 작가 등록 */
|
||||
public void authorEnroll(AuthorVO author) throws Exception;
|
||||
|
||||
/* 작가 목록 */
|
||||
public List<AuthorVO> authorGetList(Criteria cri) throws Exception;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,22 +1,39 @@
|
||||
package com.vam.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.vam.mapper.AuthorMapper;
|
||||
import com.vam.model.AuthorVO;
|
||||
import com.vam.model.Criteria;
|
||||
|
||||
@Service
|
||||
public class AuthorServiceImpl implements AuthorService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(AuthorServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
AuthorMapper authorMapper;
|
||||
|
||||
/* 작가 등록 */
|
||||
@Override
|
||||
public void authorEnroll(AuthorVO author) throws Exception {
|
||||
|
||||
authorMapper.authorEnroll(author);
|
||||
|
||||
}
|
||||
|
||||
/* 작가 목록 */
|
||||
@Override
|
||||
public List<AuthorVO> authorGetList(Criteria cri) throws Exception {
|
||||
|
||||
log.info("(service)authorGetList()......." + cri);
|
||||
|
||||
return authorMapper.authorGetList(cri);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
||||
pageEncoding="UTF-8"%>
|
||||
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
|
||||
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
@@ -20,6 +21,28 @@
|
||||
|
||||
<div class="admin_content_wrap">
|
||||
<div class="admin_content_subject"><span>작가 관리</span></div>
|
||||
<div class="author_table_wrap">
|
||||
<table class="author_table">
|
||||
<thead>
|
||||
<tr>
|
||||
<td class="th_column_1">작가 번호</td>
|
||||
<td class="th_column_2">작가 이름</td>
|
||||
<td class="th_column_3">작가 국가</td>
|
||||
<td class="th_column_4">등록 날짜</td>
|
||||
<td class="th_column_5">수정 날짜</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<c:forEach items="${list}" var="list">
|
||||
<tr>
|
||||
<td><c:out value="${list.authorId}"></c:out> </td>
|
||||
<td><c:out value="${list.authorName}"></c:out></td>
|
||||
<td><c:out value="${list.nationName}"></c:out> </td>
|
||||
<td><fmt:formatDate value="${list.regDate}" pattern="yyyy-MM-dd"/></td>
|
||||
<td><fmt:formatDate value="${list.updateDate}" pattern="yyyy-MM-dd"/></td>
|
||||
</tr>
|
||||
</c:forEach>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%@include file="../includes/admin/footer.jsp" %>
|
||||
|
||||
@@ -107,6 +107,41 @@ ul{
|
||||
color: white;
|
||||
}
|
||||
|
||||
/* 작가 목록 영역 */
|
||||
.author_table_wrap{
|
||||
padding: 20px 35px
|
||||
}
|
||||
.author_table{
|
||||
width: 100%;
|
||||
border: 1px solid #d3d8e1;
|
||||
text-align: center;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
.author_table td{
|
||||
padding: 10px 5px;
|
||||
border : 1px solid #e9ebf0;
|
||||
}
|
||||
.author_table thead{
|
||||
background-color: #f8f9fd;
|
||||
font-weight: 600;
|
||||
}
|
||||
.th_column_1{
|
||||
width:120px;
|
||||
}
|
||||
.th_column_3{
|
||||
width:110px;
|
||||
}
|
||||
.th_column_4{
|
||||
width:140px;
|
||||
}
|
||||
.th_column_5{
|
||||
width:140px;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* footer navai 영역 */
|
||||
.footer_nav{
|
||||
width:100%;
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package com.vam.service;
|
||||
|
||||
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.AuthorVO;
|
||||
import com.vam.model.Criteria;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("file:src/main/webapp/WEB-INF/spring/root-context.xml")
|
||||
@@ -16,6 +18,8 @@ public class AuthorServiceTests {
|
||||
@Autowired
|
||||
private AuthorService service;
|
||||
|
||||
/* 작가 등록 테스트 */
|
||||
/*
|
||||
@Test
|
||||
public void authorEnrollTest() throws Exception {
|
||||
|
||||
@@ -28,5 +32,20 @@ public class AuthorServiceTests {
|
||||
service.authorEnroll(author);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
/* 작가 목록 구현 */
|
||||
@Test
|
||||
public void authorGetListTest() throws Exception{
|
||||
|
||||
Criteria cri = new Criteria(3, 10);
|
||||
|
||||
List list = service.authorGetList(cri);
|
||||
|
||||
for(int i = 0; i < list.size(); i++) {
|
||||
System.out.println("list" + i + "......." + list.get(i));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
package com.vam.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
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.model.Criteria;
|
||||
import com.vam.service.AuthorService;
|
||||
|
||||
@Controller
|
||||
@@ -20,7 +24,6 @@ public class AdminController {
|
||||
@Autowired
|
||||
private AuthorService authorService;
|
||||
|
||||
|
||||
/* 관리자 메인 페이지 이동 */
|
||||
@RequestMapping(value="main", method = RequestMethod.GET)
|
||||
public void adminMainGET() throws Exception{
|
||||
@@ -49,8 +52,15 @@ public class AdminController {
|
||||
|
||||
/* 작가 관리 페이지 접속 */
|
||||
@RequestMapping(value = "authorManage", method = RequestMethod.GET)
|
||||
public void authorManageGET() throws Exception{
|
||||
logger.info("작가 관리 페이지 접속");
|
||||
public void authorManageGET(Criteria cri, Model model) throws Exception{
|
||||
|
||||
logger.info("작가 관리 페이지 접속.........." + cri);
|
||||
|
||||
/* 작가 목록 출력 데이터 */
|
||||
List list = authorService.authorGetList(cri);
|
||||
|
||||
model.addAttribute("list", list);
|
||||
|
||||
}
|
||||
|
||||
/* 작가 등록 */
|
||||
|
||||
@@ -47,6 +47,11 @@ public class AuthorVO {
|
||||
|
||||
public void setNationId(String nationId) {
|
||||
this.nationId = nationId;
|
||||
if(nationId.equals("01")) {
|
||||
this.nationName = "국내";
|
||||
} else {
|
||||
this.nationName = "국외";
|
||||
}
|
||||
}
|
||||
|
||||
public String getNationName() {
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
package com.vam.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.vam.model.AuthorVO;
|
||||
import com.vam.model.Criteria;
|
||||
|
||||
public interface AuthorService {
|
||||
|
||||
/* 작가 등록 */
|
||||
public void authorEnroll(AuthorVO author) throws Exception;
|
||||
|
||||
/* 작가 목록 */
|
||||
public List<AuthorVO> authorGetList(Criteria cri) throws Exception;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,22 +1,39 @@
|
||||
package com.vam.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.vam.mapper.AuthorMapper;
|
||||
import com.vam.model.AuthorVO;
|
||||
import com.vam.model.Criteria;
|
||||
|
||||
@Service
|
||||
public class AuthorServiceImpl implements AuthorService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(AuthorServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
AuthorMapper authorMapper;
|
||||
|
||||
/* 작가 등록 */
|
||||
@Override
|
||||
public void authorEnroll(AuthorVO author) throws Exception {
|
||||
|
||||
authorMapper.authorEnroll(author);
|
||||
|
||||
}
|
||||
|
||||
/* 작가 목록 */
|
||||
@Override
|
||||
public List<AuthorVO> authorGetList(Criteria cri) throws Exception {
|
||||
|
||||
log.info("(service)authorGetList()......." + cri);
|
||||
|
||||
return authorMapper.authorGetList(cri);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
||||
pageEncoding="UTF-8"%>
|
||||
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
|
||||
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
@@ -20,6 +21,28 @@
|
||||
|
||||
<div class="admin_content_wrap">
|
||||
<div class="admin_content_subject"><span>작가 관리</span></div>
|
||||
<div class="author_table_wrap">
|
||||
<table class="author_table">
|
||||
<thead>
|
||||
<tr>
|
||||
<td class="th_column_1">작가 번호</td>
|
||||
<td class="th_column_2">작가 이름</td>
|
||||
<td class="th_column_3">작가 국가</td>
|
||||
<td class="th_column_4">등록 날짜</td>
|
||||
<td class="th_column_5">수정 날짜</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<c:forEach items="${list}" var="list">
|
||||
<tr>
|
||||
<td><c:out value="${list.authorId}"></c:out> </td>
|
||||
<td><c:out value="${list.authorName}"></c:out></td>
|
||||
<td><c:out value="${list.nationName}"></c:out> </td>
|
||||
<td><fmt:formatDate value="${list.regDate}" pattern="yyyy-MM-dd"/></td>
|
||||
<td><fmt:formatDate value="${list.updateDate}" pattern="yyyy-MM-dd"/></td>
|
||||
</tr>
|
||||
</c:forEach>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%@include file="../includes/admin/footer.jsp" %>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Insert title here</title>
|
||||
<link rel="stylesheet" href="../resources/css/admin/authorEnroll.css">
|
||||
<link rel="stylesheet" href="../resources/css/admin/main.css">
|
||||
|
||||
<script
|
||||
src="https://code.jquery.com/jquery-3.4.1.js"
|
||||
@@ -14,114 +14,13 @@
|
||||
</head>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<%@include file="../includes/admin/header.jsp" %>
|
||||
|
||||
<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">
|
||||
<span id="warn_authorName">작가 이름을 입력 해주세요.</span>
|
||||
</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>
|
||||
<span id="warn_nationId">소속 국가를 선택해주세요.</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form_section">
|
||||
<div class="form_section_title">
|
||||
<label>작가소개</label>
|
||||
</div>
|
||||
<div class="form_section_content">
|
||||
<input name="authorIntro" type="text">
|
||||
<span id="warn_authorIntro">작가 소개를 입력 해주세요.</span>
|
||||
</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>
|
||||
</div>
|
||||
|
||||
<%@include file="../includes/admin/footer.jsp" %>
|
||||
|
||||
<script>
|
||||
|
||||
/* 등록 버튼 */
|
||||
$("#enrollBtn").click(function(){
|
||||
/* 검사 통과 유무 변수 */
|
||||
let nameCheck = false; // 작가 이름
|
||||
let nationCheck = false; // 소속 국가
|
||||
let introCheck = false; // 작가 소개
|
||||
|
||||
/* 입력값 변수 */
|
||||
let authorName = $('input[name=authorName]').val(); // 작가 이름
|
||||
let nationId = $('select[name=nationId]').val(); // 소속 국가
|
||||
let authorIntro = $('input[name=authorIntro]').val(); // 작가 소개
|
||||
/* 공란 경고 span태그 */
|
||||
let wAuthorName = $('#warn_authorName');
|
||||
let wNationId = $('#warn_nationId');
|
||||
let wAuthorIntro = $('#warn_authorIntro');
|
||||
|
||||
/* 작기 이름 공란 체크 */
|
||||
if(authorName ===''){
|
||||
wAuthorName.css('display', 'block');
|
||||
nameCheck = false;
|
||||
} else{
|
||||
wAuthorName.css('display', 'none');
|
||||
nameCheck = true;
|
||||
}
|
||||
|
||||
/* 소속 국가 공란 체크 */
|
||||
if(nationId ==='none'){
|
||||
wNationId.css('display', 'block');
|
||||
nationCheck = false;
|
||||
} else{
|
||||
wNationId.css('display', 'none');
|
||||
nationCheck = true;
|
||||
}
|
||||
|
||||
/* 작가 소개 공란 체크 */
|
||||
if(authorIntro ===''){
|
||||
wAuthorIntro.css('display', 'block');
|
||||
introCheck = false;
|
||||
} else{
|
||||
wAuthorIntro.css('display', 'none');
|
||||
introCheck = true;
|
||||
}
|
||||
|
||||
/* 최종 검사 */
|
||||
if(nameCheck && nationCheck && introCheck){
|
||||
$("#enrollForm").submit();
|
||||
} else{
|
||||
return;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/* 취소 버튼 */
|
||||
$("#cancelBtn").click(function(){
|
||||
location.href="/admin/authorManage"
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -107,6 +107,41 @@ ul{
|
||||
color: white;
|
||||
}
|
||||
|
||||
/* 작가 목록 영역 */
|
||||
.author_table_wrap{
|
||||
padding: 20px 35px
|
||||
}
|
||||
.author_table{
|
||||
width: 100%;
|
||||
border: 1px solid #d3d8e1;
|
||||
text-align: center;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
.author_table td{
|
||||
padding: 10px 5px;
|
||||
border : 1px solid #e9ebf0;
|
||||
}
|
||||
.author_table thead{
|
||||
background-color: #f8f9fd;
|
||||
font-weight: 600;
|
||||
}
|
||||
.th_column_1{
|
||||
width:120px;
|
||||
}
|
||||
.th_column_3{
|
||||
width:110px;
|
||||
}
|
||||
.th_column_4{
|
||||
width:140px;
|
||||
}
|
||||
.th_column_5{
|
||||
width:140px;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* footer navai 영역 */
|
||||
.footer_nav{
|
||||
width:100%;
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.vam.service;
|
||||
|
||||
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.AuthorVO;
|
||||
import com.vam.model.Criteria;
|
||||
|
||||
@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);
|
||||
|
||||
}
|
||||
|
||||
/* 작가 목록 구현 */
|
||||
@Test
|
||||
public void authorGetListTest() throws Exception{
|
||||
|
||||
Criteria cri = new Criteria(3, 10);
|
||||
|
||||
List list = service.authorGetList(cri);
|
||||
|
||||
for(int i = 0; i < list.size(); i++) {
|
||||
System.out.println("list" + i + "......." + list.get(i));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user