본문 바로가기
🍁 Spring/🍃SpringBoot

[SpringBoot]스프링부트로 펜션예약페이지만들기!!(1일차)

by 김말자 2022. 8. 8.
728x90
728x90
BIG

팀원 2명 저, B

 

프로젝트명

성공펜션예약프로젝트

 

개발환경

스프링부트

마이바티스

오라클디비

mvc패턴

 

 

스토리보드

메인화면이 필요하고, 소개페이지, 예약페이지, 그거에대한 Q&A페이지가 필요하다는걸 깨달음

소개페이지는 B

예약페이지는 제가 만들기로 구상하고 회의를 마침

 

 

 

구상

팀원분을 성함을 밝히기가 그래서 B님으로 함

그분께서 정리한걸 ppt로 만들었는데 너무 잘만들었음.

 

 

예약페이지

이런식으로 만들기위해 Calendar클래스를 이용해 보려고한다.

1차

컨트롤러


import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

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 com.example.pension.dto.DateData;
@Controller       //컨트롤러어노테이션 걸어둠
public class CalendarController {
@RequestMapping(value = "/") // / 사인이 들어오면 home탭을 일단 calendar로 설정해놓음
public String home() {

return "calendar";   //리턴값 설정
}

@RequestMapping(value = "calendar.do", method = RequestMethod.GET) //get방식으로 calendar를 받기로함
public String calendar(Model model, HttpServletRequest request, DateData dateData){

Calendar cal = Calendar.getInstance();
DateData calendarData; //dto

 

dto 는 

public class DateData {

String year = "";
String month = "";
String date = "";
String value = "";

 

 

 

getter, setter 걸어주고

 

 

public Map<String, Integer> today_info(DateData dateData) {  // 캘린더 함수 삽입
Map<String, Integer> today_Data = new HashMap<String, Integer>(); //hashmap
Calendar cal = Calendar.getInstance();
cal.set(Integer.parseInt(dateData.getYear()), Integer.parseInt(dateData.getMonth()), 1);

int startDay = cal.getMinimum(java.util.Calendar.DATE);
int endDay = cal.getActualMaximum(java.util.Calendar.DAY_OF_MONTH);
int start = cal.get(java.util.Calendar.DAY_OF_WEEK);

Calendar todayCal = Calendar.getInstance();
SimpleDateFormat ysdf = new SimpleDateFormat("yyyy"); //표현방식
SimpleDateFormat msdf = new SimpleDateFormat("M");

//오늘 년월
int today_year = Integer.parseInt(ysdf.format(todayCal.getTime()));
int today_month = Integer.parseInt(msdf.format(todayCal.getTime()));

int search_year = Integer.parseInt(dateData.getYear());
int search_month = Integer.parseInt(dateData.getMonth()) + 1;

int today = -1; //0부터시작되기떄문
if (today_year == search_year && today_month == search_month) {
SimpleDateFormat dsdf = new SimpleDateFormat("dd");
today = Integer.parseInt(dsdf.format(todayCal.getTime()));
}

search_month = search_month-1; 

Map<String, Integer> before_after_calendar = before_after_calendar(search_year,search_month);


System.out.println("search_month : " + search_month);

today_Data.put("start", start);
today_Data.put("startDay", startDay);
today_Data.put("endDay", endDay);
today_Data.put("today", today);
today_Data.put("search_year", search_year);
today_Data.put("search_month", search_month+1);
today_Data.put("before_year", before_after_calendar.get("before_year"));
today_Data.put("before_month", before_after_calendar.get("before_month"));
today_Data.put("after_year", before_after_calendar.get("after_year"));
today_Data.put("after_month", before_after_calendar.get("after_month"));
return today_Data;
}

private Map<String, Integer> before_after_calendar(int search_year, int search_month){
Map<String, Integer> before_after_data = new HashMap<String, Integer>();
int before_year = search_year;
int before_month = search_month-1;
int after_year = search_year;
int after_month = search_month+1;

if(before_month<0){
before_month=11;
before_year=search_year-1;
}

if(after_month>11){
after_month=0;
after_year=search_year+1;
}

before_after_data.put("before_year", before_year);
before_after_data.put("before_month", before_month);
before_after_data.put("after_year", after_year);
before_after_data.put("after_month", after_month);

return before_after_data;
}

 


if(dateData.getDate().equals("")&&dateData.getMonth().equals("")){
dateData = new DateData(String.valueOf(cal.get(Calendar.YEAR)),String.valueOf(cal.get(Calendar.MONTH)),String.valueOf(cal.get(Calendar.DATE)),null);
}

Map<String, Integer> today_info =  dateData.today_info(dateData);
List<DateData> dateList = new ArrayList<DateData>();

for(int i=1; i<today_info.get("start"); i++){
calendarData= new DateData(null, null, null, null);
dateList.add(calendarData);
}
for (int i = today_info.get("startDay"); i <= today_info.get("endDay"); i++) {
if(i==today_info.get("today")){
calendarData= new DateData(String.valueOf(dateData.getYear()), String.valueOf(dateData.getMonth()), String.valueOf(i), "today");
}else{
calendarData= new DateData(String.valueOf(dateData.getYear()), String.valueOf(dateData.getMonth()), String.valueOf(i), "normal_date");
}
dateList.add(calendarData);
}

int index = 7-dateList.size()%7;

if(dateList.size()%7!=0){

for (int i = 0; i < index; i++) {
calendarData= new DateData(null, null, null, null);
dateList.add(calendarData);
}
}
System.out.println(dateList);

//배열에 담음
model.addAttribute("dateList", dateList); //날짜 데이터 배열
model.addAttribute("today_info", today_info);
return "calendar";
}
}

 

 

그 후

 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Calendar"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<html lang="ko">
<head>
   <title>예약하기</title> //타이틀 삽입 
   <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/resources/css/reservationCSS.css">
 
   <meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body>
<form name="calendarFrm" id="calendarFrm" action="register_list" method="GET">
<SPAN ID=calendar1 STYLE="position:relative;"></SPAN>
<input type="button" class="today_button" onclick="admin" value="관리자"/> 
<script type="text/javascript"> showCalendar(nowd,nowm,nowy);</script>
<center><br />예약을 원하는 것을 선택해 주세요.<br />
(클릭시 해당 날짜의 예약 현황 페이지로 이동합니다.)<br />
<a href="main">홈으로 이동</a></center> //아직 안검



<div class="calendar" >

   <!--날짜 네비게이션  -->
   <div class="navigation">
      <a class="before_after_year" href="./calendar.do?year=${today_info.search_year-1}&month=${today_info.search_month-1}">
         &lt;&lt;
      <!-- 이전해 -->
      </a> 
      <a class="before_after_month" href="./calendar.do?year=${today_info.before_year}&month=${today_info.before_month}">
         &lt;
      <!-- 이전달 -->
      </a> 
      <span class="this_month">
         &nbsp;${today_info.search_year}. 
         <c:if test="${today_info.search_month<10}">0</c:if>${today_info.search_month}
      </span>
      <a class="before_after_month" href="/calendar.do?year=${today_info.after_year}&month=${today_info.after_month}">
      <!-- 다음달 -->
         &gt;
      </a> 
      <a class="before_after_year" href="/calendar.do?year=${today_info.search_year+1}&month=${today_info.search_month-1}">
         <!-- 다음해 -->
         &gt;&gt;
      </a>
   </div>

<div class="today_button_div">
<input type="button" class="today_button" onclick="javascript:location.href='/calendar.do'" value="오늘"/> 
</div>
<table class="calendar_body">

<thead>
   <tr bgcolor="#CECECE">
      <td class="day sun" >
         일
      </td>
      <td class="day" >
         월
      </td>
      <td class="day" >
         화
      </td>
      <td class="day" >
         수
      </td>
      <td class="day" >
         목
      </td>
      <td class="day" >
         금
      </td>
      <td class="day sat" >
         토
      </td>
   </tr>
</thead>
<tbody>
   <tr>
      <c:forEach var="dateList" items="${dateList}" varStatus="date_status">
         <c:choose>
            <c:when test="${dateList.value=='today'}">
               <td class="today">
                  <div class="date">
                     <a href = "main.jsp">${dateList.date}</a>
                             <c:out value="예약종료">예약가능</c:out>
                  </div>
                  <div>
                  </div>
               </td>
            </c:when>
            <c:when test="${date_status.index%7==6}">
               <td class="sat_day">
                  <div class="sat">
      <a href = "main.jsp">${dateList.date}</a>
              <c:out value="예약종료">예약가능</c:out>
                  </div>
                  <div>
                  </div>
               </td>
            </c:when>
            <c:when test="${date_status.index%7==0}">
   </tr>
   <tr>
      <td class="sun_day">
         <div class="sun">
                 <a href = "main.jsp">${dateList.date}</a>
                         <c:out value="예약종료">예약가능</c:out>
         </div>
         <div>
         </div>
      </td>
            </c:when>
            <c:otherwise>
      <td class="normal_day">
         <div class="date">
                <a href = "main.jsp">${dateList.date}</a>
                        <c:out value="예약종료">예약가능</c:out>
         </div>
         <div>
 
            <c:choose>
           
                                       <c:when test="${dateList.month eq 6 and dateList.date eq 24}">
                               <span>극성수기<span>
                    </c:when>
                                       <c:when test="${dateList.month eq 6 and dateList.date eq 25}">
                               <span>극성수기<span>
                    </c:when>
                                       <c:when test="${dateList.month eq 6 and dateList.date eq 26}">
                               <span>극성수기<span>
                    </c:when>
                                       <c:when test="${dateList.month eq 6 and dateList.date eq 27}">
                               <span>극성수기<span>
                    </c:when>
                                       <c:when test="${dateList.month eq 6 and dateList.date eq 28}">
                               <span>극성수기<span>
                    </c:when>
                                       <c:when test="${dateList.month eq 6 and dateList.date eq 29}">
                               <span>극성수기<span>
                    </c:when>                   <c:when test="${dateList.month eq 6 and dateList.date eq 30}">
                               <span>극성수기<span>
                    </c:when>                   <c:when test="${dateList.month eq 7 and dateList.date eq 1}">
                               <span>극성수기<span>
                    </c:when>                   <c:when test="${dateList.month eq 7 and dateList.date eq 2}">
                               <span>극성수기<span>
                    </c:when>
               </c:choose>
         </div>
      </td>
            </c:otherwise>
         </c:choose>

      </c:forEach>
</tbody>

</table>
</div>
</form>
</body>
</html>

 

 

계획

일단 디비를 넣고, 오라클 디비에 넣고 if문을 넣어서 예약가능과 예약종료 그부분을 만들어놓기

728x90
반응형
BIG

댓글