본문 바로가기
SPRING

230303_Tiles

by 경 훈 2023. 3. 3.

 

<%@ 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>
<c:choose>
	<c:when test="${param.result == 'loginfail'}">
		<script type="text/javascript">
			alert('아이디와 비밀번호를 확인하시오')		
		</script>
		<div class="alert alert-danger">
			<strong>위험!!!!</strong>
			당신은 <a href="login" class="alert-link"> 아이디와 비밀번호를 확인후 다시 로그인을 시도</a>.
		</div>
	</c:when>
	<c:when test="${param.result == 'loginfail2'}">
		<script type="text/javascript">
			alert('로그인을 하셔야 사용가능합니다')
		</script>
		<div class="alert alert-danger">
			<strong>위험!!!!</strong>
			로그인을 <a href="login" class="alert-link"> 하셔야 사용가능한 메뉴입니다.</a>.
		</div>
	</c:when>
</c:choose>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<header>
<h1 align="center">
OO 도서관 도서현황 v1.1
</h1>
</header>
</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="/kim9_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="in">입력</a></li>
          <li><a href="out">출력</a></li>
          <li><a href="search">검색</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="sellout">출고현황</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="mem">회원가입</a></li>
            <li><a href="login">로그인</a></li>
          	<li><a href="logout">로그아웃</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="mem"><span class="glyphicon glyphicon-user"></span>회원가입</a></li>
	      	<li><a href="login"><span class="glyphicon glyphicon-log-in"></span>로그인</a></li>
    	</c:otherwise>
    	</c:choose>
    	</ul>
        </li>
	</div>
  </div>
</nav>
</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>
	<form action="save" method="post" enctype="multipart/form-data">
		<table border="1" align="center">
			<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><input type="date" name="day"></td>
			</tr>
			<tr>
				<th>가격</th>
				<td><input type="text" name="price"></td>
			</tr>
			<tr>
				<th>내용</th>
				<td>
					<textarea rows="10" cols="30" name="bigo"></textarea>
				</td>
			</tr>
			<tr>
				<th>표지</th>
				<td><input type="file" name="picture"></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/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="1000px">
		<tr>
			<th>도서번호</th><th>도서명</th><th>저자명</th><th>출판일자</th><th>가격</th><th>표지</th>
			<th>비고</th><th>판매</th>
		</tr>
		<c:forEach items="${list}" var="list">
		<tr>
			<td>${list.num}</td>
			<td>${list.bname}</td>
			<td>${list.writer}</td>
			<td>
				<fmt:parseDate value='${list.day}' var='day1' pattern='yyyy-MM-dd' scope="page"/>
				<fmt:formatDate value="${day1}" pattern="yyyy-MM-dd"/>
			</td>
			<td><fmt:formatNumber value="${list.price}" pattern="#,##0"/></td>
			<td>
				<a href="out2?bname=${list.bname}">
					<img src="resources/${list.picture}" width="60px" height="100px">
				</a>
			</td>
			<td>
				<a href="delete?bname=${list.bname}">&#10060;</a>
				<a href="modify?bname=${list.bname}">&#9989;</a>
			</td>
			<td>
				<a href="sell?bname=${list.bname}"><button>판매완료</button></a>
			</td>
		</tr>
		</c:forEach>
	</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/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">
		<tr>
			<th>도서명</th><th>내용</th><th>표지</th>
		</tr>
		<c:forEach items="${list2}" var="list2">
		<tr>
			<td>${list2.bname}</td>
			<td>${list2.bigo}</td>
			<td>
				<a href="out">
				<img src="resources/${list2.picture}" width="100px" height="150px">
				</a>
			</td>
		</tr>
		</c:forEach>
	</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/fmt" prefix="fmt"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<h3 align="center">
	수정
	</h3>
	<form action="modify2" method="post" enctype="multipart/form-data">
		<table border="1" align="center">
			<c:forEach items="${list3}" var="list3">
			<tr>
				<th>도서명</th>
				<td><input type="text" name="bname" value="${list3.bname}"></td>
			</tr>
			<tr>
				<th>저자명</th>
				<td><input type="text" name="writer" value="${list3.writer}"></td>
			</tr>
			<tr>
				<th>출판일자</th>
				<td><input type="date" name="day" value="${list3.day}"></td>
			</tr>
			<tr>
				<th>가격</th>
				<td><input type="text" name="price" value="${list3.price}"></td>
			</tr>
			<tr>
				<th>내용</th>
				<td>
					<textarea rows="10" cols="30" name="bigo">${list3.bigo}</textarea>
				</td>
			</tr>
			<tr>
				<th>표지</th>
				<td><input type="file" name="picture"></td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<input type="submit" value="수정">
					<input type="reset" value="리셋">
				</td>
			</tr>
			</c:forEach>
		</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="search2">
		<table border="1" align="center">
			<tr>
				<th>검색조건</th>
				<td>
					<select name="item">
						<option value="bname">도서명
						<option value="writer">저자명
						<option value="bigo">내용
					</select>
				</td>
			</tr>
			<tr>
				<th>검색내용</th>
				<td><input type="text" name="value"></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"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<h3 align="center">
	회원가입
	</h3>
	<form action="membersave" method="post">
		<table border="1" align="center">
			<tr>
				<th>아이디</th>
				<td><input type="text" name="id"></td>
			</tr>
			<tr>
				<th>비밀번호</th>
				<td><input type="password" name="pw"></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"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<h3 align="center">
	로그인
	</h3>
	<form action="logincheck">
		<table border="1" align="center">
			<tr>
				<th>아이디</th>
				<td><input type="text" name="id"></td>
			</tr>
			<tr>
				<th>비밀번호</th>
				<td><input type="password" name="pw"></td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<input type="submit" value="로그인">
					<a href="mem">
					<input type="button" value="회원가입">
					</a>
				</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/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="1000px">
		<tr>
			<th>도서번호</th><th>판매횟수</th><th>총판매금액</th>
			<th>도서명</th><th>저자명</th><th>가격</th><th>표지</th>
			
		</tr>
		<c:forEach items="${list}" var="list">
		<tr>
			<td>${list.num}</td>
			<td>${list.count}</td>
			<td><fmt:formatNumber value="${list.price*list.count}" pattern="#,##0"/></td>
			<td>${list.bname}</td>
			<td>${list.writer}</td>
			<td><fmt:formatNumber value="${list.price}" pattern="#,##0"/></td>
			<td>
				<a href="out2?bname=${list.bname}">
					<img src="resources/${list.picture}" width="60px" height="100px">
				</a>
			</td>
		</tr>
		</c:forEach>
	</table>
</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="input" extends="baseLayout">
		<put-attribute name="title" value="입력폼"/>
		<put-attribute name="body" value="/WEB-INF/views/input.jsp"/>
	</definition>  
	<definition name="output" extends="baseLayout">
		<put-attribute name="title" value="출력폼"/>
		<put-attribute name="body" value="/WEB-INF/views/output.jsp"/>
	</definition>  
	<definition name="output2" extends="baseLayout">
		<put-attribute name="title" value="출력폼2"/>
		<put-attribute name="body" value="/WEB-INF/views/output2.jsp"/>
	</definition>  
	<definition name="modifyform" extends="baseLayout">
		<put-attribute name="title" value="수정폼"/>
		<put-attribute name="body" value="/WEB-INF/views/modifyform.jsp"/>
	</definition>  
	<definition name="searchform" extends="baseLayout">
		<put-attribute name="title" value="검색폼"/>
		<put-attribute name="body" value="/WEB-INF/views/searchform.jsp"/>
	</definition>  
	<definition name="memberinput" extends="baseLayout">
		<put-attribute name="title" value="회원가입폼"/>
		<put-attribute name="body" value="/WEB-INF/views/memberinput.jsp"/>
	</definition>  
	<definition name="loginform" extends="baseLayout">
		<put-attribute name="title" value="로그인폼"/>
		<put-attribute name="body" value="/WEB-INF/views/loginform.jsp"/>
	</definition>  
	<definition name="selloutput" extends="baseLayout">
		<put-attribute name="title" value="출고현황"/>
		<put-attribute name="body" value="/WEB-INF/views/selloutput.jsp"/>
	</definition>  
</tiles-definitions>

package com.ezen.kim9_001;

public class BookDTO {
	int num;
	String bname,writer,day,bigo;
	int price;
	String picture;
	public BookDTO() {
	}
	public BookDTO(int num, String bname, String writer, String day, String bigo, int price, String picture) {
		super();
		this.num = num;
		this.bname = bname;
		this.writer = writer;
		this.day = day;
		this.bigo = bigo;
		this.price = price;
		this.picture = picture;
	}
	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 getDay() {
		return day;
	}
	public void setDay(String day) {
		this.day = day;
	}
	public String getBigo() {
		return bigo;
	}
	public void setBigo(String bigo) {
		this.bigo = bigo;
	}
	public int getPrice() {
		return price;
	}
	public void setPrice(int price) {
		this.price = price;
	}
	public String getPicture() {
		return picture;
	}
	public void setPicture(String picture) {
		this.picture = picture;
	}
}

 

package com.ezen.kim9_001;

public class MemberDTO {
	String id,pw;

	public MemberDTO() {
	}
	public MemberDTO(String id, String pw) {
		super();
		this.id = id;
		this.pw = pw;
	}
	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;
	}
}

 

package com.ezen.kim9_001;

public class BookDTO2 {
	int num;
	String bname,writer;
	int price;
	String picture;
	int count;
	public BookDTO2() {
	}
	public BookDTO2(int num, String bname, String writer, int price, String picture, int count) {
		super();
		this.num = num;
		this.bname = bname;
		this.writer = writer;
		this.price = price;
		this.picture = picture;
		this.count = count;
	}
	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 int getPrice() {
		return price;
	}
	public void setPrice(int price) {
		this.price = price;
	}
	public String getPicture() {
		return picture;
	}
	public void setPicture(String picture) {
		this.picture = picture;
	}
	public int getCount() {
		return count;
	}
	public void setCount(int count) {
		this.count = count;
	}
}

 

package com.ezen.kim9_001;

import java.util.ArrayList;

public interface Service {
	public void insert(String bname,String writer,String day,int price,String bigo,String picture);
	public ArrayList<BookDTO> out();
	public ArrayList<BookDTO> out2(String bname);
	public void delete(String bname);
	public ArrayList<BookDTO> modify1(String bname);
	public void modify2(String bname,String writer,String day,int price,String bigo,String picture);
	public ArrayList<BookDTO> searchbname(String value);
	public ArrayList<BookDTO> searchwriter(String value);
	public ArrayList<BookDTO> searchbigo(String value);
	public void memberinsert(String id,String pw);
	public MemberDTO logincheck(String id,String pw);
	public BookDTO sell(String bname);
	public void sellinsert(int num,String bname,String writer,int price,String picture,int count);
	public BookDTO2 sellcheck(String bname);
	public void sellupdate(int num,int count);
	public ArrayList<BookDTO2> sellout();
}

 

<?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.kim9_001.Service">
	<insert id="insert">
		insert into db03031 values (bnum2_seq.nextval,#{param1},#{param2},#{param3},#{param4},#{param5},#{param6})
	</insert>
	<select id="out" resultType="com.ezen.kim9_001.BookDTO">
		select * from db03031
	</select>
	<select id="out2" resultType="com.ezen.kim9_001.BookDTO">
		select * from db03031 where bname = #{param1}
	</select>
	<delete id="delete">
		delete from db03031 where bname = #{param1}
	</delete>
	<select id="modify1" resultType="com.ezen.kim9_001.BookDTO">
		select * from db03031 where bname = #{param1}
	</select>
	<update id="modify2">
		update db03031 set writer=#{param2},day=#{param3},price=#{param4},bigo=#{param5},picture=#{param6} where bname=#{param1}
	</update>
	<select id="searchbname" resultType="com.ezen.kim9_001.BookDTO">
		select * from db03031 where bname like '%'||#{param1}||'%'
	</select>
	<select id="searchwriter" resultType="com.ezen.kim9_001.BookDTO">
		select * from db03031 where writer like '%'||#{param1}||'%'
	</select>
	<select id="searchbigo" resultType="com.ezen.kim9_001.BookDTO">
		select * from db03031 where bigo like '%'||#{param1}||'%'
	</select>
	<insert id="memberinsert">
		insert into db03032 values (#{param1},#{param2})
	</insert>
	<select id="logincheck" resultType="com.ezen.kim9_001.MemberDTO">
		select * from db03032 where id=#{param1} and pw=#{param2}
	</select>
	<select id="sell" resultType="com.ezen.kim9_001.BookDTO">
		select * from db03031 where bname = #{param1}
	</select>
	<insert id="sellinsert">
		insert into db03033 values (#{param1},#{param2},#{param3},#{param4},#{param5},#{param6})
	</insert>
	<select id="sellcheck" resultType="com.ezen.kim9_001.BookDTO2">
		select num,count from db03033 where bname = #{param1}
	</select>
	<update id="sellupdate">
		update db03033 set count=#{param2} where num=#{param1}
	</update>
	<select id="sellout" resultType="com.ezen.kim9_001.BookDTO2">
		select * from db03033 order by num asc
	</select>
	
</mapper>

 

package com.ezen.kim9_001;

import java.io.File;
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.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

@Controller
public class HomeController {
	@Autowired
	SqlSession sqlsession;
	@RequestMapping(value="/")
	public String ko1() {
		return "main";
	}
	@RequestMapping(value="/in")
	public String ko2(HttpServletRequest request,RedirectAttributes ra) {
		HttpSession hs = request.getSession();
		if(hs.getAttribute("dto")==null) {
			ra.addAttribute("result","loginfail2");
			return "redirect:login";
		}
		return "input";
	}
	@RequestMapping(value="/save")
	public String ko3(MultipartHttpServletRequest mul) {
		String bname = mul.getParameter("bname");
		String writer = mul.getParameter("writer");
		String day = mul.getParameter("day");
		int price = Integer.parseInt(mul.getParameter("price"));
		String bigo = mul.getParameter("bigo");
		MultipartFile mf = mul.getFile("picture");
		String picture = mf.getOriginalFilename();
		String uploadpath = "C:\\12월국비\\spring\\day9_001\\src\\main\\webapp\\resources";
		File saveFile = new File(uploadpath,picture);
		try {
			mf.transferTo(saveFile);
		}catch (Exception e) {
			e.printStackTrace();
		} 
		Service ss = sqlsession.getMapper(Service.class);
		ss.insert(bname,writer,day,price,bigo,picture);
		return "redirect:in";
	}
	@RequestMapping(value="/out")
	public String ko4(Model mo) {
		Service ss = sqlsession.getMapper(Service.class);
		ArrayList<BookDTO> list = ss.out();
		mo.addAttribute("list", list);
		return "output";
	}
	@RequestMapping(value="/out2")
	public String ko5(HttpServletRequest request,Model mo) {
		String bname = request.getParameter("bname");
		Service ss = sqlsession.getMapper(Service.class);
		ArrayList<BookDTO> list2 = ss.out2(bname);
		mo.addAttribute("list2", list2);
		return "output2";
	}
	@RequestMapping(value="/delete")
	public String ko6(HttpServletRequest request) {
		String bname = request.getParameter("bname");
		Service ss = sqlsession.getMapper(Service.class);
		ss.delete(bname);
		return "redirect:out";
	}
	@RequestMapping(value="/modify")
	public String ko7(HttpServletRequest request,Model mo) {
		String bname = request.getParameter("bname");
		Service ss = sqlsession.getMapper(Service.class);
		ArrayList<BookDTO> list3 = ss.modify1(bname);
		mo.addAttribute("list3", list3);
		return "modifyform";
	}
	@RequestMapping(value="/modify2")
	public String ko8(MultipartHttpServletRequest mul) {
		String bname = mul.getParameter("bname");
		String writer = mul.getParameter("writer");
		String day = mul.getParameter("day");
		int price = Integer.parseInt(mul.getParameter("price"));
		String bigo = mul.getParameter("bigo");
		MultipartFile mf = mul.getFile("picture");
		String picture = mf.getOriginalFilename();
		Service ss = sqlsession.getMapper(Service.class);
		ss.modify2(bname,writer,day,price,bigo,picture);
		return "redirect:out";
	}
	@RequestMapping(value="/search")
	public String ko9() {
		return "searchform";
	}
	@RequestMapping(value="/search2")
	public String ko10(HttpServletRequest request,Model mo) {
		String item = request.getParameter("item");
		String value = request.getParameter("value");
		Service ss = sqlsession.getMapper(Service.class);
		if(item.equals("bname")) {
			ArrayList<BookDTO> list = ss.searchbname(value);
			mo.addAttribute("list", list);
		}
		else if(item.equals("writer")) {
			ArrayList<BookDTO> list = ss.searchwriter(value);
			mo.addAttribute("list", list);
		}
		else {
			ArrayList<BookDTO> list = ss.searchbigo(value);
			mo.addAttribute("list", list);
		}
		return "output";
	}
	@RequestMapping(value="/mem")
	public String ko11() {
		return "memberinput";
	}
	@RequestMapping(value="/login")
	public String ko12() {
		return "loginform";
	}
	@RequestMapping(value="/membersave")
	public String ko13(HttpServletRequest request) {
		String id = request.getParameter("id");
		String pw = request.getParameter("pw");
		Service ss = sqlsession.getMapper(Service.class);
		ss.memberinsert(id, pw);
		return "redirect:mem";
	}
	@RequestMapping(value="/logincheck")
	public String ko14(HttpServletRequest request,RedirectAttributes ra) {
		String id = request.getParameter("id");
		String pw = request.getParameter("pw");
		Service ss = sqlsession.getMapper(Service.class);
		MemberDTO dto = ss.logincheck(id, pw);
		HttpSession hs = request.getSession();
		if(dto!=null) {
			hs.setAttribute("dto", dto);
			hs.setAttribute("login", true);
			hs.setMaxInactiveInterval(240);
		}
		else {
			ra.addAttribute("result","loginfail");
			return "redirect:login";
		}
		return "main";
	}
	@RequestMapping(value="/logout")
	public String ko15(HttpServletRequest request) {
		Service ss = sqlsession.getMapper(Service.class);
		HttpSession hs = request.getSession();
		hs.removeAttribute("dto");
		hs.removeAttribute("login");
		hs.setAttribute("login", false);
		return "main";
	}
	@RequestMapping(value="/sell")
	public String ko16(HttpServletRequest request,Model mo) {
		String bname = request.getParameter("bname");
		Service ss = sqlsession.getMapper(Service.class);
		BookDTO2 dto2 = ss.sellcheck(bname);
		if(dto2==null) {
			BookDTO dto = ss.sell(bname);
			int num = dto.getNum();
			bname = dto.getBname();
			String writer = dto.getWriter();
			int price = dto.getPrice();
			String picture = dto.getPicture();
			int count = 1;
			ss.sellinsert(num,bname,writer,price,picture,count);
		}
		else {
			int num = dto2.getNum();
			int count = dto2.getCount()+1;
			ss.sellupdate(num,count);
		}
		return "redirect:out";
	}
	@RequestMapping(value="/sellout")
	public String ko17(Model mo) {
		Service ss = sqlsession.getMapper(Service.class);
		ArrayList<BookDTO2> list = ss.sellout();
		mo.addAttribute("list", list);
		return "selloutput";
	}
}

 

'SPRING' 카테고리의 다른 글

230307_Tiles  (0) 2023.03.07
230306_Tiles  (0) 2023.03.06
230302_Tiles  (0) 2023.03.02
230228_Tiles  (0) 2023.02.28
230227_MyBatis  (0) 2023.02.27

댓글