본문 바로가기
SPRING

230302_Tiles

by 경 훈 2023. 3. 2.
<%@ 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.0
</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="/kim8_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="memberin">회원가입</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="memberin"><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>
	</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">
		<table border="1" align="center">
			<tr>
				<th>주문날짜</th>
				<td><input type="date" name="day"></td>
			</tr>
			<tr>
				<th>주문코드</th>
				<td>
					<select name="spcode">
						<option value="ap">사과
						<option value="ma">망고
						<option value="wa">수박
						<option value="me">참외
					</select>
				</td>
			</tr>
			<tr>
				<th>수량</th>
				<td><input type="text" name="su"></td>
			</tr>
			<tr>
				<th>단가</th>
				<td><input type="text" name="danga"></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>
	<c:choose>
		<c:when test="${login == true && dto != null}">
		<h3 align="center">
		출력
		</h3>
		<table border="1" align="center">
			<tr>
				<th>주문날짜</th><th>상품명</th><th>총액</th>
			</tr>
			<c:forEach items="${list}" var="list">
			<tr>
				<td>
					<fmt:parseDate value='${list.day}' var='day' pattern='yyyymmdd'/>
					<fmt:formatDate value="${day}" pattern="yyyy-MM-dd"/>
				</td>
				<td>${list.spname}</td>
				<td><fmt:formatNumber value="${list.price}" pattern="#,##0"/></td>
			</tr>
			</c:forEach>
		</table>
		</c:when>
		<c:otherwise>
			<script type="text/javascript">
				window.onload=function() {
					alert("아웃폼은 로그인 후에 사용가능합니다.")
					window.location.href = 'login';
				}
			</script>
		</c:otherwise>
	</c:choose>
</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="spcode">
						<option value="ap">사과
						<option value="ma">망고
						<option value="wa">수박
						<option value="me">참외
					</select>
				</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>
	<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>
	<form action="membercheck" 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="로그인">
					<a href="memberin"><input type="button" value="회원가입"></a>
				</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="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="memberinput" extends="baseLayout">
		<put-attribute name="title" value="회원가입폼"/>
		<put-attribute name="body" value="/WEB-INF/views/memberinput.jsp"/>
	</definition>  
	<definition name="login" extends="baseLayout">
		<put-attribute name="title" value="로그인폼"/>
		<put-attribute name="body" value="/WEB-INF/views/login.jsp"/>
	</definition>  
	<definition name="searchform" extends="baseLayout">
		<put-attribute name="title" value="검색폼"/>
		<put-attribute name="body" value="/WEB-INF/views/searchform.jsp"/>
	</definition>
</tiles-definitions>

 

package com.ezen.kim8_001;

import java.util.ArrayList;

public interface Service {
	public void insert(String day,String spcode,int su,int danga,int price);
	public ArrayList<MarketDTO> out();
	public void memberinsert(String id,String pw);
	public MemberDTO logincheck(String id,String pw);
	public ArrayList<MarketDTO> searchout(String spcode);
}

 

<?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.kim8_001.Service">
	<insert id="insert">
		insert into db03021 values (#{param1},#{param2},#{param3},#{param4},#{param5})
	</insert>
	<select id="out" resultType="com.ezen.kim8_001.MarketDTO">
		select * from db03021 db1, db03023 db3 where db1.spcode = db3.spcode
	</select>
	<insert id="memberinsert">
		insert into db03022 values (#{param1},#{param2})
	</insert>
	<select id="logincheck" resultType="com.ezen.kim8_001.MemberDTO">
		select * from db03022 where id=#{param1} and pw=#{param2}
	</select>
	<select id="searchout" resultType="com.ezen.kim8_001.MarketDTO">
		select * from db03021 db1, db03023 db3 where db1.spcode = db3.spcode and db1.spcode = #{param1}
	</select>
</mapper>

 

package com.ezen.kim8_001;

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.servlet.mvc.support.RedirectAttributes;

@Controller
public class HomeController {
	@Autowired
	SqlSession sqlsession;
	@RequestMapping(value="/")
	public String ko1() {
		return "main";
	}
	@RequestMapping(value="/in")
	public String ko2(HttpSession hs,RedirectAttributes ra) {
		if(hs.getAttribute("dto")==null) {
			ra.addAttribute("result","loginfail2");
			return "redirect:login";
		}
		else {
			return "input";
		}
	}
	@RequestMapping(value="/save")
	public String ko3(HttpServletRequest request) {
		String day = request.getParameter("day");
		String spcode = request.getParameter("spcode");
		int su = Integer.parseInt(request.getParameter("su"));
		int danga = Integer.parseInt(request.getParameter("danga"));
		int price = su*danga;
		Service ss = sqlsession.getMapper(Service.class);
		ss.insert(day,spcode,su,danga,price);
		return "redirect:in";
	}
	@RequestMapping(value="/out")
	public String ko4(Model mo) {
		Service ss = sqlsession.getMapper(Service.class);
		ArrayList<MarketDTO> list = ss.out();
		mo.addAttribute("list", list);
		return "output";
	}
	@RequestMapping(value="/memberin")
	public String ko5() {
		return "memberinput";
	}
	@RequestMapping(value="/membersave")
	public String ko6(HttpServletRequest request) {
		String id = request.getParameter("id");
		String pw = request.getParameter("pw");
		Service ss = sqlsession.getMapper(Service.class);
		ss.memberinsert(id,pw);
		return "redirect:memberin";
	}
	@RequestMapping(value="/login")
	public String ko7() {
		return "login";
	}
	@RequestMapping(value="/membercheck")
	public String ko8(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("login", true);
			hs.setAttribute("dto", dto);
			hs.setMaxInactiveInterval(60);
		}
		else {
			ra.addAttribute("result","loginfail");
			return "redirect:login";
		}
		return "main";
	}
	@RequestMapping(value="/logout")
	public String ko9(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="/search")
	public String ko10() {
		return "searchform";
	}
	@RequestMapping(value="/search2")
	public String ko11(HttpServletRequest request,Model mo) {
		String spcode = request.getParameter("spcode");
		Service ss = sqlsession.getMapper(Service.class);
		ArrayList<MarketDTO> list = ss.searchout(spcode);
		mo.addAttribute("list", list);
		return "output";
	}
}

 

'SPRING' 카테고리의 다른 글

230306_Tiles  (0) 2023.03.06
230303_Tiles  (0) 2023.03.03
230228_Tiles  (0) 2023.02.28
230227_MyBatis  (0) 2023.02.27
230224_MyBatis  (0) 2023.02.24

댓글