<%@ 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>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<c:choose>
<c:when test="${param.result == 'loginfail'}">
<script type="text/javascript">
Swal.fire({
position: 'center',
icon: 'error',
title: '아이디 혹은 비밀번호가 틀림',
showConfirmButton: false,
timer: 1500
})
</script>
</c:when>
</c:choose>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<header>
<h1 align="center">
도서 관리 프로그램
</h1>
</header>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/kim17_001/">HOME</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="active">
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">멤버<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="memberin">입력</a></li>
<li><a href="memberout">출력</a></li>
</ul>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">도서관리<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="bookin">입력</a></li>
<li><a href="bookout">출력</a></li>
<li><a href="booksearch">검색</a></li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<c:choose>
<c:when test="${login==true && dto != null}">
<li><a href="logout">${dto.id}님 환영합니다</a></li>
<li><a href="logout"><span class="glyphicon glyphicon-log-out"></span>로그아웃</a></li>
</c:when>
<c:otherwise>
<li><a href="memberin"><span class="glyphicon glyphicon-user"></span>회원가입</a></li>
<li><a href="loginin"><span class="glyphicon glyphicon-log-in"></span>로그인</a></li>
</c:otherwise>
</c:choose>
</ul>
</div>
</div>
</nav>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-3.6.0.min.js"></script>
<link rel="stylesheet" href="//code.jauery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code,jwuery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<meta charset="UTF-8">
<script type="text/javascript">
$(function() {
$("#check").click(function(){
var id = $("#id").val();
if(id==""){
alert("아이디가 없음");
$("#id").focus();
return;
}
var idcheck =$("#idcheck").attr("idcheck");
if(idcheck=="" || idcheck=="N") {
alert("아이디 중복검사 해주세요!");
$("#idcheck").focus();
return;
}
$("#form1").submit();
});
$("#idcheck").click(function() {
var id = $("#id").val();
$.ajax({
type:"post",
async:true,
dataType:"text",
url:"idcheck",
data:{"id":id},
success:function(cnt){
if(cnt==0) {
$('#idcheck').attr('idcheck','Y');
Swal.fire({
position: 'center',
icon: 'success',
title: '사용가능한 아이디',
showConfirmButton: false,
timer: 1500
})
}
else {
$('#idcheck').attr('idcheck','N');
Swal.fire({
position: 'center',
icon: 'error',
title: '중복된 아이디',
showConfirmButton: false,
timer: 1500
})
}
}
});
});
});
</script>
<title>Insert title here</title>
</head>
<body>
<h3 align="center">회원가입</h3>
<form action="membersave" method="post" id="form1">
<table border="1" align="center">
<tr>
<th>아이디</th>
<td>
<input type="text" name="id" id="id">
<input type="button" idcheck="" id="idcheck" value="중복체크">
</td>
</tr>
<tr>
<th>비밀번호</th>
<td><input type="text" name="pw"></td>
</tr>
<tr>
<th>이름</th>
<td><input type="text" name="name"></td>
</tr>
<tr>
<th>전화번호</th>
<td><input type="text" name="phone"></td>
</tr>
<tr>
<th>생일</th>
<td><input type="date" name="birth"></td>
</tr>
<tr>
<th>거주지</th>
<td><input type="text" name="address"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="button" id="check" value="중복검사체크전송">
<input type="submit" value="전송">
<input type="reset" value="취소">
</td>
</tr>
</table>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3 align="center">회원출력</h3>
<table border="1" align="center" width="800px">
<tr>
<th>아이디</th><th>이름</th><th>전화</th><th>생일</th><th>거주지</th>
</tr>
<c:forEach items="${list}" var="list">
<tr>
<td>${list.id}</td><td>${list.name}</td><td>${list.phone}</td>
<td>
<c:set var="birth" value="${list.birth}"/>
${fn:substring(birth,0,10)}
</td>
<td>${list.address}</td>
</tr>
</c:forEach>
<tr style="border-left:none;border-right:none;border-bottom:none">
<td colspan="5" style="text-align: center;">
<c:if test="${paging.startPage !=1}">
<a href="memberout?nowPage=${paging.startPage-1}&cntPerPage=${paging.cntPerPage}">◀</a>
</c:if>
<c:forEach begin="${paging.startPage}" end="${paging.endPage}" var="p">
<c:choose>
<c:when test="${p == paging.nowPage}">
<b><span style="color:red;font-family:bold">${p}</span></b>
</c:when>
<c:when test="${p != paging.nowPage}">
<a href="memberout?nowPage=${p}&cntPerPage=${paging.cntPerPage}">${p}</a>
</c:when>
</c:choose>
</c:forEach>
<c:if test="${paging.endPage != paging.lastPage}">
<a href="memberout?nowPage=${paging.endPage+1}&cntPerPage=${paging.cntPerPage}">▶</a>
</c:if>
</td>
</tr>
</table>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3 align="center">로그인</h3>
<form action="logincheck" method="post">
<table border="1" align="center">
<tr>
<th>아이디</th>
<td><input type="text" name="id"></td>
</tr>
<tr>
<th>비밀번호</th>
<td><input type="text" name="pw"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="로그인">
<a href="memberin"><input type="button" value="회원가입"></a>
</td>
</tr>
</table>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3 align="center">도서입력</h3>
<form action="booksave" method="post" enctype="multipart/form-data">
<table border="1" align="center">
<tr>
<th>번호</th>
<td><input type="text" name="num"></td>
</tr>
<tr>
<th>도서명</th>
<td><input type="text" name="bname"></td>
</tr>
<tr>
<th>저자</th>
<td><input type="text" name="writer"></td>
</tr>
<tr>
<th>내용</th>
<td>
<textarea rows="10" cols="30" name="bigo"></textarea>
</td>
</tr>
<tr>
<th>발간일자</th>
<td><input type="date" name="dayday"></td>
</tr>
<tr>
<th>가격</th>
<td><input type="text" name="price"></td>
</tr>
<tr>
<th>표지</th>
<td><input type="file" name="poster"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="전송">
<input type="reset" value="취소">
</td>
</tr>
</table>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3 align="center">도서출력</h3>
<table border="1" align="center" width="800px">
<tr>
<th>번호</th><th>도서명</th><th>저자</th>
<th>발간일자</th><th>가격</th><th>표지</th><th>수정</th>
</tr>
<c:forEach items="${list}" var="list">
<tr>
<td>
<a href="bookdelete?num=${list.num}">${list.num}</a>
</td>
<td>
<a href="bookout2?bname=${list.bname}">${list.bname}</a>
</td>
<td>${list.writer}</td>
<td>
<c:set var="dayday" value="${list.dayday}"/>
${fn:substring(dayday,0,10)}
</td>
<td>
<fmt:formatNumber value="${list.price}" pattern="#,##0"/>
</td>
<td>
<img src="resources/${list.poster}" width="60px" height="80px">
</td>
<td>
<a href="bookmodify?bname=${list.bname}">✅</a>
</td>
</tr>
</c:forEach>
<tr style="border-left:none;border-right:none;border-bottom:none">
<td colspan="7" style="text-align: center;">
<c:if test="${paging.startPage !=1}">
<a href="memberout?nowPage=${paging.startPage-1}&cntPerPage=${paging.cntPerPage}">◀</a>
</c:if>
<c:forEach begin="${paging.startPage}" end="${paging.endPage}" var="p">
<c:choose>
<c:when test="${p == paging.nowPage}">
<b><span style="color:red;font-family:bold">${p}</span></b>
</c:when>
<c:when test="${p != paging.nowPage}">
<a href="memberout?nowPage=${p}&cntPerPage=${paging.cntPerPage}">${p}</a>
</c:when>
</c:choose>
</c:forEach>
<c:if test="${paging.endPage != paging.lastPage}">
<a href="memberout?nowPage=${paging.endPage+1}&cntPerPage=${paging.cntPerPage}">▶</a>
</c:if>
</td>
</tr>
</table>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3 align="center">도서출력2</h3>
<table border="1" align="center" width="800px">
<tr>
<th>도서명</th><th>내용</th><th>표지</th>
</tr>
<tr>
<td>${dto.bname}</td>
<td>${dto.bigo}</td>
<td>
<img src="resources/${dto.poster}" width="180px" height="240px">
</td>
</tr>
</table>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3 align="center">도서검색</h3>
<form action="booksearchout">
<table border="1" align="center">
<tr>
<th>구분</th>
<td>
<select name="items">
<option value="writer">저자</option>
<option value="bname">도서명</option>
<option value="bigo">내용</option>
</select>
</td>
</tr>
<tr>
<th>내용</th>
<td><input type="text" name="value"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="검색">
</td>
</tr>
</table>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3 align="center">도서수정</h3>
<form action="bookmodifysave" method="post" enctype="multipart/form-data">
<table border="1" align="center">
<tr>
<th>번호</th>
<td><input type="text" name="num" value="${dto.num}"></td>
</tr>
<tr>
<th>도서명</th>
<td><input type="text" name="bname" value="${dto.bname}" readonly></td>
</tr>
<tr>
<th>저자</th>
<td><input type="text" name="writer" value="${dto.writer}"></td>
</tr>
<tr>
<th>내용</th>
<td>
<textarea rows="10" cols="30" name="bigo">${dto.bigo}</textarea>
</td>
</tr>
<tr>
<th>발간일자</th>
<td><input type="date" name="dayday"></td>
</tr>
<tr>
<th>가격</th>
<td><input type="text" name="price" value="${dto.price}"></td>
</tr>
<tr>
<th>표지</th>
<td>
<input type="file" name="poster">
<img src="resources/${dto.poster}" width="40px" height="60px">
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="전송">
<input type="reset" value="취소">
</td>
</tr>
</table>
</form>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="baseLayout" template="/WEB-INF/views/layout.jsp">
<put-attribute name="title" value=""/>
<put-attribute name="top" value="/WEB-INF/views/top.jsp"/>
<put-attribute name="body" value=""/>
<put-attribute name="footer" value="/WEB-INF/views/footer.jsp"/>
</definition>
<definition name="main" extends="baseLayout">
<put-attribute name="title" value="메인화면"/>
<put-attribute name="body" value="/WEB-INF/views/main.jsp"/>
</definition>
<definition name="memberinput" extends="baseLayout">
<put-attribute name="title" value="회원가입"/>
<put-attribute name="body" value="/WEB-INF/views/member/memberinput.jsp"/>
</definition>
<definition name="logininput" extends="baseLayout">
<put-attribute name="title" value="로그인"/>
<put-attribute name="body" value="/WEB-INF/views/member/logininput.jsp"/>
</definition>
<definition name="memberoutput" extends="baseLayout">
<put-attribute name="title" value="회원출력"/>
<put-attribute name="body" value="/WEB-INF/views/member/memberoutput.jsp"/>
</definition>
<definition name="bookinput" extends="baseLayout">
<put-attribute name="title" value="도서입력"/>
<put-attribute name="body" value="/WEB-INF/views/book/bookinput.jsp"/>
</definition>
<definition name="bookoutput" extends="baseLayout">
<put-attribute name="title" value="도서출력"/>
<put-attribute name="body" value="/WEB-INF/views/book/bookoutput.jsp"/>
</definition>
<definition name="bookoutput2" extends="baseLayout">
<put-attribute name="title" value="도서출력2"/>
<put-attribute name="body" value="/WEB-INF/views/book/bookoutput2.jsp"/>
</definition>
<definition name="booksearch" extends="baseLayout">
<put-attribute name="title" value="도서검색"/>
<put-attribute name="body" value="/WEB-INF/views/book/booksearch.jsp"/>
</definition>
<definition name="bookmodify2" extends="baseLayout">
<put-attribute name="title" value="도서수정폼"/>
<put-attribute name="body" value="/WEB-INF/views/book/bookmodify2.jsp"/>
</definition>
</tiles-definitions>
package com.ezen.kim17_001.member;
public class MemberDTO {
String id,pw,name,phone,birth,address;
public MemberDTO() {
}
public MemberDTO(String id, String pw, String name, String phone, String birth, String address) {
super();
this.id = id;
this.pw = pw;
this.name = name;
this.phone = phone;
this.birth = birth;
this.address = address;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPw() {
return pw;
}
public void setPw(String pw) {
this.pw = pw;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getBirth() {
return birth;
}
public void setBirth(String birth) {
this.birth = birth;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
package com.ezen.kim17_001.member;
public class PageDTO {
// 현재페이지,시작페이지,끝페이지,레코드총갯수,페이지당레코드의수,전체페이지,쿼리 start, end
private int nowPage, startPage, endPage, total, cntPerPage, lastPage, start, end;
private int cntPage=5; //한 화면에 표시하고자 하는 페이의 수
public int getCntPage() {
return cntPage;
}
public void setCntPage(int cntPage) {
this.cntPage = cntPage;
}
public PageDTO() {
}
public PageDTO(int total, int nowPage, int cntPerPage) {
setNowPage(nowPage);
setCntPerPage(cntPerPage);
setTotal(total);
calcLastPage(getTotal(), getCntPerPage());
calcStartEndPage(getNowPage(), cntPage);
calcStartEnd(getNowPage(), getCntPerPage());
}
//전체 페이지 수
public void calcLastPage(int total, int cntPerPage) {
setLastPage((int) Math.ceil((double)total / (double)cntPerPage));
}
//시작페이지와 끝 페이지
public void calcStartEndPage(int nowPage, int cntPage) {
setEndPage(((int)Math.ceil((double)nowPage / (double)cntPage)) * cntPage);
if (getLastPage() < getEndPage()) {
setEndPage(getLastPage());
}
setStartPage(getEndPage() - cntPage + 1);
if(getStartPage()<1) {
setStartPage(1);
}
}
// DB쿼리에 정의할 start,end
public void calcStartEnd(int nowPage, int cntPerPage) {
setEnd(nowPage * cntPerPage);
setStart(getEnd() - cntPerPage + 1);
}
public int getNowPage() {
return nowPage;
}
public void setNowPage(int nowPage) {
this.nowPage = nowPage;
}
public int getStartPage() {
return startPage;
}
public void setStartPage(int startPage) {
this.startPage = startPage;
}
public int getEndPage() {
return endPage;
}
public void setEndPage(int endPage) {
this.endPage = endPage;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public int getCntPerPage() {
return cntPerPage;
}
public void setCntPerPage(int cntPerPage) {
this.cntPerPage = cntPerPage;
}
public int getLastPage() {
return lastPage;
}
public void setLastPage(int lastPage) {
this.lastPage = lastPage;
}
public int getStart() {
return start;
}
public void setStart(int start) {
this.start = start;
}
public int getEnd() {
return end;
}
public void setEnd(int end) {
this.end = end;
}
}
package com.ezen.kim17_001.member;
import java.util.ArrayList;
public interface Service1 {
public void insert(String id,String pw,String name,String phone,String birth,String address);
public String idcheck(String id);
public MemberDTO logincheck(String id , String pw);
public int cntnotice();
public ArrayList<MemberDTO> out(PageDTO dto);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ezen.kim17_001.member.Service1">
<insert id="insert">
insert into member0315 values (#{param1},#{param2},#{param3},#{param4},#{param5},#{param6})
</insert>
<select id="idcheck" resultType="String">
select count(*) from member0315 where id = #{param1}
</select>
<select id="logincheck" resultType="com.ezen.kim17_001.member.MemberDTO">
select * from member0315 where id = #{param1} and pw = #{param2}
</select>
<select id="cntnotice" resultType="int">
select count(*) from member0315
</select>
<select id="out" resultType="com.ezen.kim17_001.member.MemberDTO">
select * from (
select rownum rn,A.* from(
select * from member0315)A)
where rn between #{start} AND #{end}
</select>
</mapper>
package com.ezen.kim17_001.member;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.ibatis.session.SqlSession;
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.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
@Controller
public class MemberController {
@Autowired
SqlSession sqlsession;
@RequestMapping(value="/memberin")
public String ko1() {
return "memberinput";
}
@RequestMapping(value="/membersave")
public String ko2(HttpServletRequest request) {
String id = request.getParameter("id");
String pw = request.getParameter("pw");
String name = request.getParameter("name");
String phone = request.getParameter("phone");
String birth = request.getParameter("birth");
String address = request.getParameter("address");
Service1 ss1 = sqlsession.getMapper(Service1.class);
ss1.insert(id,pw,name,phone,birth,address);
return "redirect:memberin";
}
@ResponseBody
@RequestMapping(value="/idcheck",method = RequestMethod.POST)
public String ko3(String id) {
Service1 ss1 = sqlsession.getMapper(Service1.class);
String cnt = ss1.idcheck(id);
return cnt;
}
@RequestMapping(value="/loginin")
public String ko4() {
return "logininput";
}
@RequestMapping(value="/logincheck")
public String ko5(HttpServletRequest request,RedirectAttributes ra) {
String id = request.getParameter("id");
String pw = request.getParameter("pw");
Service1 ss1 = sqlsession.getMapper(Service1.class);
MemberDTO dto = ss1.logincheck(id,pw);
HttpSession hs = request.getSession();
if(dto!=null) {
hs.setAttribute("dto", dto);
hs.setAttribute("login", true);
}
else {
hs.setAttribute("login", false);
ra.addAttribute("result", "loginfail");
return "redirect:loginin";
}
return "main";
}
@RequestMapping(value="/logout")
public String ko5(HttpServletRequest request) {
Service1 ss1 = sqlsession.getMapper(Service1.class);
HttpSession hs = request.getSession();
hs.removeAttribute("dto");
hs.setAttribute("login", false);
return "main";
}
@RequestMapping(value="/memberout")
public String ko6(HttpServletRequest request,PageDTO dto,Model mo) {
String nowPage = request.getParameter("nowPage");
String cntPerPage = request.getParameter("cntPerPage");
Service1 ss1 = sqlsession.getMapper(Service1.class);
int total = ss1.cntnotice();
if(nowPage==null && cntPerPage == null) {
nowPage = "1";
cntPerPage = "5";
}
else if(nowPage==null) {
nowPage = "1";
}
else if(cntPerPage == null) {
cntPerPage = "5";
}
dto = new PageDTO(total,Integer.parseInt(nowPage),Integer.parseInt(cntPerPage));
mo.addAttribute("paging", dto);
ArrayList<MemberDTO> list = ss1.out(dto);
mo.addAttribute("list", list);
return "memberoutput";
}
}
package com.ezen.kim17_001.book;
public class BookDTO {
int num;
String bname,writer,bigo,dayday,price,poster;
public BookDTO() {
}
public BookDTO(int num, String bname, String writer, String bigo, String dayday, String price, String poster) {
super();
this.num = num;
this.bname = bname;
this.writer = writer;
this.bigo = bigo;
this.dayday = dayday;
this.price = price;
this.poster = poster;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getBname() {
return bname;
}
public void setBname(String bname) {
this.bname = bname;
}
public String getWriter() {
return writer;
}
public void setWriter(String writer) {
this.writer = writer;
}
public String getBigo() {
return bigo;
}
public void setBigo(String bigo) {
this.bigo = bigo;
}
public String getDayday() {
return dayday;
}
public void setDayday(String dayday) {
this.dayday = dayday;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getPoster() {
return poster;
}
public void setPoster(String poster) {
this.poster = poster;
}
}
package com.ezen.kim17_001.book;
public class PageDTO {
// 현재페이지,시작페이지,끝페이지,레코드총갯수,페이지당레코드의수,전체페이지,쿼리 start, end
private int nowPage, startPage, endPage, total, cntPerPage, lastPage, start, end;
private int cntPage=10; //한 화면에 표시하고자 하는 페이의 수
public int getCntPage() {
return cntPage;
}
public void setCntPage(int cntPage) {
this.cntPage = cntPage;
}
public PageDTO() {
}
public PageDTO(int total, int nowPage, int cntPerPage) {
setNowPage(nowPage);
setCntPerPage(cntPerPage);
setTotal(total);
calcLastPage(getTotal(), getCntPerPage());
calcStartEndPage(getNowPage(), cntPage);
calcStartEnd(getNowPage(), getCntPerPage());
}
//전체 페이지 수
public void calcLastPage(int total, int cntPerPage) {
setLastPage((int) Math.ceil((double)total / (double)cntPerPage));
}
//시작페이지와 끝 페이지
public void calcStartEndPage(int nowPage, int cntPage) {
setEndPage(((int)Math.ceil((double)nowPage / (double)cntPage)) * cntPage);
if (getLastPage() < getEndPage()) {
setEndPage(getLastPage());
}
setStartPage(getEndPage() - cntPage + 1);
if(getStartPage()<1) {
setStartPage(1);
}
}
// DB쿼리에 정의할 start,end
public void calcStartEnd(int nowPage, int cntPerPage) {
setEnd(nowPage * cntPerPage);
setStart(getEnd() - cntPerPage + 1);
}
public int getNowPage() {
return nowPage;
}
public void setNowPage(int nowPage) {
this.nowPage = nowPage;
}
public int getStartPage() {
return startPage;
}
public void setStartPage(int startPage) {
this.startPage = startPage;
}
public int getEndPage() {
return endPage;
}
public void setEndPage(int endPage) {
this.endPage = endPage;
}
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public int getCntPerPage() {
return cntPerPage;
}
public void setCntPerPage(int cntPerPage) {
this.cntPerPage = cntPerPage;
}
public int getLastPage() {
return lastPage;
}
public void setLastPage(int lastPage) {
this.lastPage = lastPage;
}
public int getStart() {
return start;
}
public void setStart(int start) {
this.start = start;
}
public int getEnd() {
return end;
}
public void setEnd(int end) {
this.end = end;
}
}
package com.ezen.kim17_001.book;
import java.util.ArrayList;
public interface Service2 {
public void insert(int num,String bname,String writer,String bigo,String dayday,int price,String poster);
public int cntnotice();
public ArrayList<BookDTO> out(PageDTO dto);
public BookDTO out2(String bname);
public void delete(int num);
public ArrayList<BookDTO> searchwriter(String value);
public ArrayList<BookDTO> searchbname(String value);
public ArrayList<BookDTO> searchbigo(String value);
public BookDTO modify2(String bname);
public void modifysave(int num,String bname,String writer,String bigo,String dayday,int price,String poster);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ezen.kim17_001.book.Service2">
<insert id="insert">
insert into book0315 values (#{param1},#{param2},#{param3},#{param4},#{param5},#{param6},#{param7})
</insert>
<select id="cntnotice" resultType="int">
select count(*) from book0315
</select>
<select id="out" resultType="com.ezen.kim17_001.book.BookDTO">
select * from (
select rownum rn,A.* from(
select * from book0315)A)
where rn between #{start} AND #{end}
</select>
<select id="out2" resultType="com.ezen.kim17_001.book.BookDTO">
select * from book0315 where bname = #{param1}
</select>
<delete id="delete">
delete from book0315 where num = #{param1}
</delete>
<select id="searchwriter" resultType="com.ezen.kim17_001.book.BookDTO">
select * from book0315 where writer like '%'||#{param1}||'%'
</select>
<select id="searchbname" resultType="com.ezen.kim17_001.book.BookDTO">
select * from book0315 where bname like '%'||#{param1}||'%'
</select>
<select id="searchbigo" resultType="com.ezen.kim17_001.book.BookDTO">
select * from book0315 where bigo like '%'||#{param1}||'%'
</select>
<select id="modify2" resultType="com.ezen.kim17_001.book.BookDTO">
select * from book0315 where bname = #{param1}
</select>
<update id="modifysave">
update book0315 set num=#{param1},writer=#{param3},bigo=#{param4},dayday=#{param5},price=#{param6},poster=#{param7} where bname=#{param2}
</update>
</mapper>
package com.ezen.kim17_001.book;
import java.io.File;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import org.apache.ibatis.session.SqlSession;
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.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
@Controller
public class BookController {
@Autowired
SqlSession sqlsession;
@RequestMapping(value="/bookin")
public String ko1() {
return "bookinput";
}
@RequestMapping(value="/booksave")
public String ko2(MultipartHttpServletRequest mul) throws Exception {
int num = Integer.parseInt(mul.getParameter("num"));
String bname = mul.getParameter("bname");
String writer = mul.getParameter("writer");
String bigo = mul.getParameter("bigo");
String dayday = mul.getParameter("dayday");
int price = Integer.parseInt(mul.getParameter("price"));
MultipartFile mf = mul.getFile("poster");
String poster = mf.getOriginalFilename();
String path = "C:\\12월국비\\spring\\day17_001\\src\\main\\webapp\\resources";
mf.transferTo(new File(path,poster));
Service2 ss2 = sqlsession.getMapper(Service2.class);
ss2.insert(num,bname,writer,bigo,dayday,price,poster);
return "redirect:bookin";
}
@RequestMapping(value="/bookout")
public String ko3(HttpServletRequest request,PageDTO dto,Model mo) {
String nowPage = request.getParameter("nowPage");
String cntPerPage = request.getParameter("cntPerPage");
Service2 ss2 = sqlsession.getMapper(Service2.class);
int total = ss2.cntnotice();
if(nowPage==null && cntPerPage == null) {
nowPage = "1";
cntPerPage = "10";
}
else if(nowPage==null) {
nowPage = "1";
}
else if(cntPerPage == null) {
cntPerPage = "10";
}
dto = new PageDTO(total,Integer.parseInt(nowPage),Integer.parseInt(cntPerPage));
mo.addAttribute("paging", dto);
ArrayList<BookDTO> list = ss2.out(dto);
mo.addAttribute("list", list);
return "bookoutput";
}
@RequestMapping(value="/bookout2")
public String ko4(HttpServletRequest request,Model mo) {
String bname = request.getParameter("bname");
Service2 ss2 = sqlsession.getMapper(Service2.class);
BookDTO dto = ss2.out2(bname);
mo.addAttribute("dto", dto);
return "bookoutput2";
}
@RequestMapping(value="/bookdelete")
public String ko5(HttpServletRequest request) {
int num = Integer.parseInt(request.getParameter("num"));
Service2 ss2 = sqlsession.getMapper(Service2.class);
ss2.delete(num);
return "redirect:bookout";
}
@RequestMapping(value="/booksearch")
public String ko6() {
return "booksearch";
}
@RequestMapping(value="/booksearchout")
public String ko7(HttpServletRequest request,Model mo) {
Service2 ss2 = sqlsession.getMapper(Service2.class);
String items = request.getParameter("items");
String value = request.getParameter("value");
ArrayList<BookDTO> list = null;
if(items.equals("writer")) {
list = ss2.searchwriter(value);
}
else if(items.equals("bname")) {
list = ss2.searchbname(value);
}
else {
list = ss2.searchbigo(value);
}
mo.addAttribute("list", list);
return "bookoutput";
}
@RequestMapping(value="/bookmodify")
public String ko8(HttpServletRequest request,Model mo) {
String bname = request.getParameter("bname");
Service2 ss2 = sqlsession.getMapper(Service2.class);
BookDTO dto = ss2.modify2(bname);
mo.addAttribute("dto", dto);
return "bookmodify2";
}
@RequestMapping(value="/bookmodifysave")
public String ko9(MultipartHttpServletRequest mul) throws Exception {
int num = Integer.parseInt(mul.getParameter("num"));
String bname = mul.getParameter("bname");
String writer = mul.getParameter("writer");
String bigo = mul.getParameter("bigo");
String dayday = mul.getParameter("dayday");
int price = Integer.parseInt(mul.getParameter("price"));
MultipartFile mf = mul.getFile("poster");
String poster = mf.getOriginalFilename();
String path = "C:\\12월국비\\spring\\day17_001\\src\\main\\webapp\\resources";
mf.transferTo(new File(path,poster));
Service2 ss2 = sqlsession.getMapper(Service2.class);
ss2.modifysave(num,bname,writer,bigo,dayday,price,poster);
return "redirect:bookout";
}
}
'SPRING' 카테고리의 다른 글
230317_게시판 (0) | 2023.03.17 |
---|---|
230316_게시판 (0) | 2023.03.16 |
230314_게시판 (0) | 2023.03.14 |
230313_게시판 (0) | 2023.03.13 |
230310_AJAX (0) | 2023.03.10 |
댓글