🍁 프로젝트 설명
https://youtu.be/vxKK7G5AiXI
1. 예약 목록
- front-end에서 마지막으로 만들었던 통나무펜션을 적극 활용해서 아래 페이지를 완성하세요.
- booking 테이블의 데이터를 활용해서 아래와 같은 페이지를 완성하세요.
- 삭제 기능은 AJAX로 구현하세요.
2. 예약하기 페이지
- 예약하기 페이지에서 기본 유효성 검사를 포함 시키세요.
- 날짜 선택은 datepicker를 이용하세요.
- 예약 하기 기능은 AJAX로 구현하세요.
3. 예약 조회 기능
- 통나무펜션 페이지를 활용해서 예약 조회 기능을 만드세요.
- 이름과 전화번호를 입력 받고, 이를 통해서 예약 내역을 조회하세요.
- 조회 기능은 AJAX로 구현하세요.
- 조회가 될 경우 아래와 같이 얼럿창을 띄워서 예약 내역을 출력하세요.
- 조회가 안 될 경우 예약 내역이 없습니다를 출력하세요.
4. 팬션 소개 기능
- 자바스크립트를 이용하여 넘기기 버튼을 생성하여 이미지를 바꿔보세요.
- 자바스크립트를 이용하여 이미지를 선택시, 확대해보세요.
🍁 프로젝트 코드
- Java - Controller
package com.quiz.lesson06;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.quiz.lesson06.bo.BookingBO;
import com.quiz.lesson06.model.Booking;
@RequestMapping("/lesson06/booking")
@Controller
public class BookingController {
@Autowired
private BookingBO bookingBO;
// 1. 예약 목록 화면
// localhost:8080/lesson06/booking/booking_view
@GetMapping("/booking_view")
public String bookingView(Model model) {
// select DB
List<Booking> booking = bookingBO.getBookingList();
model.addAttribute("booking", booking);
return "lesson06/booking";
}
// 1. 예약 삭제
// AJAX 요청
// localhost:8080/lesson06/booking/delete_booking
@DeleteMapping("/delete_booking")
@ResponseBody
public Map<String, Object> deleteBooking (
@RequestParam("id") int id) { // "id"는 ajax에서 data: {"id":id} 여기서 온 파라미터임. ""
// delete
int rowCount = bookingBO.deleteBookingById(id);
Map<String, Object> result = new HashMap<>();
if (rowCount > 0) {
result.put("code", 1); // 1: 성공
result.put("result", "성공");
} else {
result.put("code", 500); // 500: 에러
result.put("errorMessage", "삭제하는데 실패했습니다.");
}
return result;
}
// 2. 예약하기 화면
// insert
// localhost:8080/lesson06/booking/booking_insert_view
@GetMapping("/booking_insert_view")
public String bookingInsertView() {
return "lesson06/booking_insert_layout";
}
// 2. 예약하기 기능
// 예약하기 API
// AJAX 요청
// localhost:8080/lesson06/booking/insert_booking
@ResponseBody
@PostMapping("/insert_booking")
public Map<String, Object> addBooking(
@RequestParam("name") String name, // ajax에서 넘겨준 key명과 똑같은 파라미터를 쓰는 것임!
@RequestParam("headcount") int headcount,
@RequestParam("day") int day,
@RequestParam("date") @DateTimeFormat (pattern="yyyy-MM-dd") Date date,
@RequestParam("phoneNumber") String phoneNumber){
// {"code":1, "result":"성공"}
// {"code":500, "errorMessage":"추가하는데 실패했습니다."}
// insert
int rowCount = bookingBO.addBooking(name, headcount, day, date, phoneNumber);
Map<String, Object> result = new HashMap<>(); // breakpoint
if(rowCount > 0) {
result.put("code", 1);
result.put("result", "성공");
} else {
result.put("code", 500);
result.put("errorMessage", "데이터를 추가하는데 실패했습니다.");
}
return result; // JSON String
}
// 3. 예약 조회 하면
// localhost:8080/lesson06/booking/booking_select_view
@GetMapping("/booking_select_view")
public String bookingSelectView() {
return "lesson06/booking_select_layout";
}
// 3. 예약 조회 기능
// 예약 조회 - AJAX 요청
// localhost:8080/lesson06/booking/booking_select
@ResponseBody
@GetMapping("/booking_select")
public Map<String, Object> selectBooking (
@RequestParam("name") String name,
@RequestParam("phoneNumber") String phoneNumber) {
Map<String, Object> result = new HashMap<>(); // breakpoint // Map은 항상 위에 있어야함.
//select DB - TODO - 구현을 안했는데 해야되는게 있을때 쓰는 것임.select DB
Booking booking = bookingBO.getBookingListByField(name, phoneNumber); // 데이터 한개 또는 빵개 받아옴.
if (booking == null) {
result.put("join", "조회 불가");
} else {
result.put("booking", booking);
// result.put("name", booking.getName());
// result.put("date", booking.getDate());
// result.put("day", booking.getDay());
// result.put("headCount", booking.getHeadcount());
// result.put("state", booking.getState());
}
return result;
}
// 4. 팬션 조회 화면
// select
// localhost:8080/lesson06/booking/booking_house_view
@GetMapping("/booking_house_view")
public String bookingHouseView() {
return "lesson06/booking_house_layout";
}
}
- Java - Booking (model)
package com.quiz.lesson06.model;
import java.util.Date;
public class Booking {
private int id;
private String name;
private int headcount;
private int day;
private Date date; // date
private String phoneNumber;
private String state;
private Date createdAt;
private Date updatedAt;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getHeadcount() {
return headcount;
}
public void setHeadcount(int headcount) {
this.headcount = headcount;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
}
- Java - BookingBO
package com.quiz.lesson06.bo;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.quiz.lesson06.dao.BookingMapper;
import com.quiz.lesson06.model.Booking;
@Service
public class BookingBO {
@Autowired
private BookingMapper bookingMapper;
// select
// output: List<Booking> input: x
public List<Booking> getBookingList() {
return bookingMapper.selectBookingList();
}
// delect
public int deleteBookingById(int id) {
return bookingMapper.deleteBookingById(id);
}
// insert
public int addBooking(String name, int headcount, int day, Date date, String phoneNumber) {
return bookingMapper.insertBooking(name, headcount, day, date, phoneNumber);
}
// select
public Booking getBookingListByField(String name, String phoneNumber) { // 한 행만 필요하기 때문에 Booking.
// 원래 BO에서 가공 많이함!!!
// ** Booking - 없으면 null // List - 없으면 []
// 선생님 코드.
List<Booking> bookingList = bookingMapper.selectBookingListByField(name, phoneNumber);
// [1 3 7\ - 7번만 줘야 된다. 즉 마지막 꺼를 준다.
// x - 없을 때도 체크
// 7 - 1개면 한개만 주면 됨.
if (bookingList.isEmpty()) {
return null;
}
// 비어있지 않으면 값이 있고, 마지막 인덱스에 있는 값을 돌려준다. (최신값) : 인덱스 값 얻기 위해 -1
return bookingList.get(bookingList.size() - 1);
}
}
- Java - BookingMapper
package com.quiz.lesson06.dao;
import java.util.Date;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import com.quiz.lesson06.model.Booking;
@Repository
public interface BookingMapper {
// select
public List<Booking> selectBookingList();
// delect
public int deleteBookingById(int id);
// insert
public int insertBooking(
@Param("name") String name,
@Param("headcount") int headcount,
@Param("day") int day,
@Param("date") Date date,
@Param("phoneNumber") String phoneNumber);
// select
public List<Booking> selectBookingListByField( // 한 행만 필요하기 때문에 Booking. // db에서 다가져 오기 - List<Booking>
@Param("name") String name,
@Param("phoneNumber") String phoneNumber);
}
- Java - Mapper.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!-- dtd문법 -->
<mapper namespace="com.quiz.lesson06.dao.BookingMapper">
<select id="selectBookingList" resultType="com.quiz.lesson06.model.Booking">
SELECT
`id`
,`name`
,`headcount`
,`day`
,`date`
,`phoneNumber`
,`state`
,`createdAt`
,`updatedAt`
FROM
`booking`
</select>
<delete id="deleteBookingById" parameterType="int">
DELETE
FROM
`booking`
WHERE
`id` = #{id}
</delete>
<insert id="insertBooking" parameterType="map">
INSERT INTO `booking`
(
`name`
,`headcount`
,`day`
,`date`
,`phoneNumber`
,`state`
,`createdAt`
,`updatedAt`
)
VALUES
(
#{name}
,#{headcount}
,#{day}
,#{date}
,#{phoneNumber}
,'대기중' <!--**** 고정된 글자는 ('대기중')이라고 xml에만 적어놓으면 됨. input안해도 됨. 작은따음표로 써야됨!! -->
, NOW()
, NOW()
)
</insert>
<select id="selectBookingListByField" parameterType="map" resultType="com.quiz.lesson06.model.Booking">
SELECT
`id`
,`name`
,`headcount`
,`day`
,`date`
,`phoneNumber`
,`state`
,`createdAt`
,`updatedAt`
FROM
`booking`
WHERE
`name` = #{name} AND
`phoneNumber` = #{phoneNumber}
</select>
</mapper>
- jsp - booking
<%@ 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"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>통나무 팬션</title>
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css"
integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N"
crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.6.4.js"
integrity="sha256-a9jBBRygX1Bh5lt8GZjXDzyOB+bWve9EiO7tROUtj/E="
crossorigin="anonymous"></script>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js" integrity="sha512-uto9mlQzrs59VwILcLiRYeLKPPbS/bT71da/OEBYEwcdNUk8jYIy+D176RYoop1Da+f9mvkYrmj5MCLZWEtQuA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" integrity="sha512-aOG0c6nPNzGk+5zjwyJaoRUgCdOrfSDhmMID2u4+OIslr0GjpLKo7Xm0Ao3xmpM4T8AmIouRkqwj1nrdVsLKEQ==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" type="text/css" href="/CSS/lesson06/booking.css">
</head>
<body>
<div id="wrap" class="container">
<header class=" d-flex justify-content-center align-items-center">
<jsp:include page="booking_header.jsp" />
</header>
<nav class=" d-flex">
<jsp:include page="booking_nav.jsp" />
</nav>
<section>
<jsp:include page="booking_section.jsp" />
</section>
<footer>
<jsp:include page="booking_footer.jsp" />
</footer>
</div>
</body>
</html>
- jsp - booking_select_layout
<%@ 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"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>예약하기</title>
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css"
integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N"
crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.6.4.js"
integrity="sha256-a9jBBRygX1Bh5lt8GZjXDzyOB+bWve9EiO7tROUtj/E="
crossorigin="anonymous"></script>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js" integrity="sha512-uto9mlQzrs59VwILcLiRYeLKPPbS/bT71da/OEBYEwcdNUk8jYIy+D176RYoop1Da+f9mvkYrmj5MCLZWEtQuA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" integrity="sha512-aOG0c6nPNzGk+5zjwyJaoRUgCdOrfSDhmMID2u4+OIslr0GjpLKo7Xm0Ao3xmpM4T8AmIouRkqwj1nrdVsLKEQ==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" type="text/css" href="/CSS/lesson06/booking.css">
</head>
<body>
<div id="wrap" class="container">
<header class=" d-flex justify-content-center align-items-center">
<jsp:include page="booking_header.jsp" />
</header>
<nav class=" d-flex">
<jsp:include page="booking_nav.jsp" />
</nav>
<section>
<jsp:include page="booking_select_content.jsp" />
</section>
<footer>
<jsp:include page="booking_footer.jsp" />
</footer>
</div>
</body>
</html>
- jsp - booking_select_content
<%@ 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"%>
<div>
<img id="bannerImage" src="/img/booking/test06_banner1.jpg" id=""
alt="이미지1" width="1100" height="600" class="w-100">
</div>
<article class="d-flex">
<%-- content1 --%>
<div class="content1 col-4">
<div class="font-weight-bold">
<a href="/lesson06/booking/booking_insert_view"
class="checkReservation">실시간 예약하기</a>
</div>
</div>
<%-- contetn2 --%>
<div class="content2">
<h2 class="mt-4 ml-3">예약확인</h2>
<div class="ml-3 mr-3">
<div class="d-flex justify-content-around mb-3">
<small
class="font-weight-bold text-center text-center align-items-center d-flex">이름</small>
<div class="ml-2 ">
<input id="name" type="text" class="inputName form-control">
</div>
</div>
<div class="d-flex mb-3 d-flex justify-content-around">
<small
class="font-weight-bold text-center text-center align-items-center d-flex">전화번호</small>
<div class="ml-2">
<input id="phoneNumber" type="text"
class="inputPhoneNumber form-control col-12 mr-2">
</div>
</div>
<div class="d-flex justify-content-end">
<button id="selectBtn" type="button" class="btn btn-success mr-3">조회하기</button>
</div>
</div>
</div>
<!-- content3 -->
<div class="content3 font-weight-bold text-light">
<small>예약문의:</small> 010-000-1111
</div>
</article>
<script>
$(document).ready(
function() {
$('#selectBtn').on(
'click',
function() {
// validation
let name = $("#name").val().trim();
let phoneNumber = $("#phoneNumber").val().trim();
if (name == "") {
alert("이름일 입력하세요.");
return;
}
if (phoneNumber == "") { // startWith 사용해서 전화번호 010으로 시작하는거 ~ check.
alert("전화번호를 입력하세요.");
return;
}
// ajax 호출 -> 서버 전송
$.ajax({
// request
type : "GET" // get일 때는 type 안써도 됨.
,
url : "/lesson06/booking/booking_select",
data : {
"name" : name,
"phoneNumber" : phoneNumber
} // 어떤 데이터로 넘길 것인가..? 파라미터 지정해주기!
// response
,
success : function(data) { // jquery ajax 함수가 json string을 object로 파싱해줌
if (data.join == "조회 불가") {
alert("예약 내역이 없습니다.");
} else {
//data.booking.name
alert("이름 : " + data.booking.name
+ "\n날짜 : " + data.booking.date.slice(0,10)
+ "\n일수 : " + data.booking.day
+ "\n인원 : " + data.booking.headcount
+ "\n상태 : " + data.booking.state);
location.reload(true); // 새로고침
}
}
,
error : function(request, status, error) {
alert("예약 내역을 조회하는데 실패했습니다.");
location.reload(true); // 새로고침
}
}); // ajax
}); // selectBtn
// 배너 순회
let bannerList = [ "/img/booking/test06_banner1.jpg",
"/img/booking/test06_banner2.jpg",
"/img/booking/test06_banner3.jpg",
"/img/booking/test06_banner4.jpg" ];
let currentIndex = 1;
setInterval(function() {
$('#bannerImage').attr('src', bannerList[currentIndex]) // 속성 변경 - attr
console.log(currentIndex);
currentIndex++;
// 4 - 0 1 2 3
if (currentIndex == bannerList.length) {
currentIndex = 0;
}
}, 2000); // 임명함수 , 3초 - 3000
}); // ready
</script>
- jsp - booking_section
<%@ 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"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<h1 class="text-center pt-4 mb-5 mt-3">예약 목록 보기</h1>
<table class="table text-center">
<thead>
<tr>
<th>이름</th>
<th>예약날짜</th>
<th>숙박일수</th>
<th>숙박인원</th>
<th>전화번호</th>
<th>예약상태</th>
<th>삭제</th>
</tr>
</thead>
<tbody>
<c:forEach items="${booking}" var="bookings">
<tr>
<td>${bookings.name}</td>
<td><fmt:formatDate value="${bookings.date}" pattern="yyyy년 M월 d일"/></td>
<td>${bookings.day}</td>
<td>${bookings.headcount}</td>
<td>${bookings.phoneNumber}</td>
<td>
<c:choose>
<c:when test="${bookings.state eq '대기중'}">
<span class="text-info">${bookings.state}</span>
</c:when>
<c:when test="${bookings.state eq '확정'}">
<span class="text-success">${bookings.state}</span>
</c:when>
<c:when test="${bookings.state eq '취소'}">
<span class="text-danger">${bookings.state}</span>
</c:when>
<c:otherwise>
${bookings.state}
</c:otherwise>
</c:choose>
</td>
<td>
<button type="button" class="del-btn btn btn-danger" data-bookings-id="${bookings.id}">삭제</button>
</td>
</tr>
</c:forEach>
</tbody>
</table>
<script>
$(document).ready(function() {
$('.del-btn').on('click', function() {
let id = $(this).data('bookings-id');
// alert(id);
$.ajax({
// request
type:"DELETE" //post 계열, 브라우저로 직접 치고 못들어감.
, url:"/lesson06/booking/delete_booking"
, data: {"id":id} // 파라미터 넘기기.
// response
, success:function(data) {
if(data.code == 1) {
alert("삭제 되었습니다.");
location.reload(true); // 새로고침
} else {
alert(data.errorMessage);
}
}
, error:function(request, status, error) {
alert("삭제하는데 실패했습니다. 관리자에게 문의해주세요.");
}
}); // ajax
}); // .del-btn
}); // ready
</script>
- jsp - booking_nav
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<ul class="nav-ul nav-fill w-100 d-flex align-items-center justify-content-around mt-2">
<li class="nav-li text-light font-weight-bold"><a class="nav-a " href="/lesson06/booking/booking_select_view">Home</a></li>
<li class="nav-li text-light font-weight-bold"><a class="nav-a " href="/lesson06/booking/booking_house_view">Log cabins</a></li>
<li class="nav-li text-light font-weight-bold"><a class="nav-a " href="/lesson06/booking/booking_insert_view">Booking</a></li>
<li class="nav-li text-light font-weight-bold"><a class="nav-a " href="/lesson06/booking/booking_view">Reservation</a></li>
</ul>
- jps - booking_insert_layout
<%@ 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"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>예약하기</title>
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css"
integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N"
crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.6.4.js"
integrity="sha256-a9jBBRygX1Bh5lt8GZjXDzyOB+bWve9EiO7tROUtj/E="
crossorigin="anonymous"></script>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js" integrity="sha512-uto9mlQzrs59VwILcLiRYeLKPPbS/bT71da/OEBYEwcdNUk8jYIy+D176RYoop1Da+f9mvkYrmj5MCLZWEtQuA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" integrity="sha512-aOG0c6nPNzGk+5zjwyJaoRUgCdOrfSDhmMID2u4+OIslr0GjpLKo7Xm0Ao3xmpM4T8AmIouRkqwj1nrdVsLKEQ==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" type="text/css" href="/CSS/lesson06/booking.css">
</head>
<body>
<div id="wrap" class="container">
<header class=" d-flex justify-content-center align-items-center">
<jsp:include page="booking_header.jsp" />
</header>
<nav class=" d-flex">
<jsp:include page="booking_nav.jsp" />
</nav>
<section>
<jsp:include page="booking_insert_content.jsp" />
</section>
<footer>
<jsp:include page="booking_footer.jsp" />
</footer>
</div>
</body>
</html>
- jps - booking_insert_content
<%@ 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"%>
<div class="container d-flex justify-content-center align-items-center">
<div>
<h1 class="mt-5 mb-5 text-center ">예약하기</h1>
<div class="font-weight-bold">이름</div>
<div><input id="name" class="form-control reserveInput1 mb-3"></div>
<div class="font-weight-bold">예약날짜</div>
<div><input id="date" class="form-control reserveInput1 mb-3"></div>
<div class="font-weight-bold">숙박일수</div>
<div><input id="day" class="form-control reserveInput1 col-12 mb-3"></div>
<div class="font-weight-bold">숙박인원</div>
<div><input id="headcount" class="form-control reserveInput1 col-12 mb-3"></div>
<div class="font-weight-bold">전화번호</div>
<div><input id="phoneNumber" class="form-control reserveInput1 col-12 mb-3"></div>
<div><button id="addBookingBtn" type="button" class="reserveInput1 btn btn-warning mt-5">예약하기</button></div>
</div>
</div>
<script>
$(document).ready(function() {
// datepicker
$('#date').datepicker({
dateFormat: 'yy-mm-dd'
, minDate:0 // 오늘부터 그 뒤 선택
});
// 추가
$("#addBookingBtn").on("click", function(){
// validation
let name = $("#name").val().trim();
let headcount = $("#headcount").val().trim();
let day = $("#day").val().trim();
let date = $("#date").val().trim();
let phoneNumber = $("#phoneNumber").val().trim();
if (name == "") {
alert("이름을 입력하세요.");
return;
}
if (date == "") {
alert("예약날짜를 입력하세요.");
return;
}
if (day == "") {
alert("숙박일수를 입력하세요.");
return;
}
if (isNaN(day)) { // ** 숫자가 아닌 값 들어오면 true
alert("숙박일수는 숫자만 입력 가능합니다.");
return;
}
if (day > 14) {
alert("숙박일수는 14일 이내로 가능합니다.");
return;
}
if (headcount == "") {
alert("숙박인원을 입력하세요.");
return;
}
if (headcount > 30) {
alert("숙박인원은 30명 이내로 가능합니다.");
return;
}
if (isNaN(headcount)) { // ** 숫자가 아닌 값 들어오면 true
alert("숙박인원는 숫자만 입력 가능합니다.");
return;
}
if (phoneNumber == "") {
alert("전화번호를 입력하세요.");
return;
}
if (phoneNumber.startsWith("010") == false) {
alert("010으로 시작하는 번호를 입력해주세요.");
return;
}
console.log(phoneNumber.length);
if (phoneNumber.length > 13) {
alert("전화번호는 '-'를 포함한 총 13자리 이내로 적어주세요.");
return;
}
// ajax 호출 => 서버 전송
$.ajax({
// request // *** 요청이 안되면 여기를 봐라!!!
type:"POST"
, url:"/lesson06/booking/insert_booking"
, data:{"name":name, "headcount":headcount, "day":day, "date":date,
"phoneNumber":phoneNumber}
// response
, success:function(data) { // jquery ajax 함수가 json string을 object로 파싱해줌
if (data.code = 1) {
alert(data.result);
location.href = "/lesson06/booking/booking_view"; // get방식으로 보내줌.
} else {
alert(data.errorMessage);
}
}
, error:function(request, status, error) {
alert("요청에 실패했습니다. 관리자에게 문의해주세요.");
}
}); // ajax
}); // 추가
}); // ready
</script>
- jsp - booking_house_layout
<%@ 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"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>팬션화면</title>
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css"
integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N"
crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.6.4.js"
integrity="sha256-a9jBBRygX1Bh5lt8GZjXDzyOB+bWve9EiO7tROUtj/E="
crossorigin="anonymous"></script>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js" integrity="sha512-uto9mlQzrs59VwILcLiRYeLKPPbS/bT71da/OEBYEwcdNUk8jYIy+D176RYoop1Da+f9mvkYrmj5MCLZWEtQuA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" integrity="sha512-aOG0c6nPNzGk+5zjwyJaoRUgCdOrfSDhmMID2u4+OIslr0GjpLKo7Xm0Ao3xmpM4T8AmIouRkqwj1nrdVsLKEQ==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" type="text/css" href="/CSS/lesson06/booking.css">
</head>
<body>
<div id="wrap" class="container">
<header class=" d-flex justify-content-center align-items-center">
<jsp:include page="booking_header.jsp" />
</header>
<nav class=" d-flex">
<jsp:include page="booking_nav.jsp" />
</nav>
<section>
<jsp:include page="booking_house_content.jsp" />
</section>
<footer>
<jsp:include page="booking_footer.jsp" />
</footer>
</div>
</body>
</html>
- jsp - booking_house_content
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<article class=" h-50">
<!-- 같은 폴더에 있으면 이름만 쓰면 img 첨부됨. -->
<img id="mainImg" src="/img/booking/house1.jpeg" alt="배너 이미지" width="1110px" height="450">
<div class="d-flex justify-content-between">
<button id="prev" type="button" class="btn btn-light">이전</button>
<button id="next" type="button" class="btn btn-light">다음</button>
</div>
</article>
<article class="article2 ">
<h3 class="section-text mt-5 mb-3">Best houses</h3>
<!-- article == div 같다! -->
<!-- justify-content-around : 양옆에 약간 여백이 생기면서 가운데 정렬. -->
<div class="d-flex justify-content-between align-items-center">
<div><a href="#"><img src="/img/booking/house2.jpeg" alt="이미지1" width="220px" height="230px" class="pics" ></a>
<div class="mt-3"><div class="img-text font-weight-bold">스위스 통나무 가정집</div>
<!-- <del>을 사용하면 글자에 취소선이 생김. -->
<!-- text-secondary: 회색글자 만들어짐. -->
<del class="article-text1 text-secondary">1박 150,000원</del>
<div class="font-weight-bold">💰Unavailable Now</div></div>
</div>
<div><a href="#"><img src="/img/booking/house3.jpeg" alt="이미지1" width="220px" height="230px" class="pics" ></a>
<div class="mt-3"><div class="img-text font-weight-bold">새소리에 취하기</div>
<del class="article-text1 text-secondary">1박 300,000원</del>
<div class="font-weight-bold">⛵1박 1,500,000원</div></div>
</div>
<div><a href="#"><img src="/img/booking/house4.jpeg" alt="이미지1" width="220px" height="230px" class="pics" ></a>
<div class="mt-3"><div class="img-text font-weight-bold">냇가 앞에 외톨이</div>
<del class="article-text1 text-secondary">2박 250,000원</del>
<div class="font-weight-bold">⛱ 4박 450,000원</div></div>
</div>
<div><a href="#"><img src="/img/booking/house5.jpeg" alt="이미지1" width="220px" height="230px" class="pics" ></a>
<div class="mt-3"><div class="img-text font-weight-bold">야생동물과 공존</div>
<del class="article-text1 text-secondary">8박 100,000원</del>
<div class="font-weight-bold">🎁10박 100,000원</div></div>
</div>
<div><a href="#"><img src="/img/booking/house6.jpeg" alt="이미지1" width="220px" height="230px" class="pics" ></a>
<div class="mt-3"><div class="img-text font-weight-bold">혼자있고 싶은 날</div>
<del class="article-text1 text-secondary">1박 120,000원</del>
<div class="font-weight-bold">💰1박 80,000원</div></div>
</div>
</div>
</article>
<script>
$(document).ready(function() {
var imgs = ['/img/booking/house1.jpeg', '/img/booking/house2.jpeg', '/img/booking/house3.jpeg', '/img/booking/house4.jpeg' , '/img/booking/house5.jpeg', '/img/booking/house6.jpeg'];
var currentIndex = 0;
// 다음 버튼 클릭
$("#next").on("click", function() {
currentIndex++;
if (currentIndex >= imgs.length) {
currentIndex = 0;
}
$('#mainImg').attr("src", imgs[currentIndex]);
});
// 이전 버튼 클릭
$("#prev").on("click", function() {
currentIndex--;
if (currentIndex < 0) {
currentIndex = imgs.length -1;
}
$('#mainImg').attr("src", imgs[currentIndex]);
});
}); // ready
</script>
- jsp - booking_header
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<div class="display-4 mt-2 mb-2 "><a href="/lesson06/booking/booking_select_view" class="text-dark headerText">통나무 팬션</a></div>
- jsp - booking_footer
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<small class="text-center justify-content-center align-items-center col-9 mt-4">
<div class="text-secondary">제주특별자치도 제주시 애월읍</div>
<div class="text-secondary mt-1">사업자등록번호:111-22-255222/농어촌민박사업자지정/대표:김통목</div>
<div class="text-secondary mt-1">Copyright@2023 YURIHONG. All Rights RESERVED.</div>
</small>
'Spring > Spring - projects(Web-pages)' 카테고리의 다른 글
Project - Writing-foreign-language / 외국어 글쓰기 프로그램 (0) | 2023.06.18 |
---|