[Spring][쇼핑몰 프로젝트][36] 장바구니 기능(Mapper메서드) - 2

https://kimvampa.tistory.com/261
This commit is contained in:
SeoJin Kim
2021-11-17 00:15:20 +09:00
parent ff0b4e8d40
commit ebd2f2389b
15 changed files with 1326 additions and 3 deletions

View File

@@ -0,0 +1,24 @@
package com.vam.mapper;
import java.util.List;
import com.vam.model.CartDTO;
public interface CartMapper {
/* 카트 추가 */
public int addCart(CartDTO cart);
/* 카트 삭제 */
public int deleteCart(int cartId);
/* 카트 수량 수정 */
public int modifyCount(CartDTO cart);
/* 카트 목록 */
public List<CartDTO> getCart(String memberId);
/* 카트 확인 */
public CartDTO checkCart(CartDTO cart);
}

View File

@@ -0,0 +1,105 @@
package com.vam.model;
public class CartDTO {
private int cartId;
private String memberId;
private int bookId;
private int bookCount;
//book
private String bookName;
private int bookPrice;
private double bookDiscount;
// 추가
private int salePrice;
private int totalPrice;
public int getCartId() {
return cartId;
}
public void setCartId(int cartId) {
this.cartId = cartId;
}
public String getMemberId() {
return memberId;
}
public void setMemberId(String memberId) {
this.memberId = memberId;
}
public int getBookId() {
return bookId;
}
public void setBookId(int bookId) {
this.bookId = bookId;
}
public int getBookCount() {
return bookCount;
}
public void setBookCount(int bookCount) {
this.bookCount = bookCount;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public int getBookPrice() {
return bookPrice;
}
public void setBookPrice(int bookPrice) {
this.bookPrice = bookPrice;
}
public double getBookDiscount() {
return bookDiscount;
}
public void setBookDiscount(double bookDiscount) {
this.bookDiscount = bookDiscount;
}
public int getSalePrice() {
return salePrice;
}
public int getTotalPrice() {
return totalPrice;
}
public void initSaleTotal() {
this.salePrice = (int) (this.bookPrice * (1-this.bookDiscount));
this.totalPrice = this.salePrice*this.bookCount;
}
@Override
public String toString() {
return "CartDTO [cartId=" + cartId + ", memberId=" + memberId + ", bookId=" + bookId + ", bookCount="
+ bookCount + ", bookName=" + bookName + ", bookPrice=" + bookPrice + ", bookDiscount=" + bookDiscount
+ ", salePrice=" + salePrice + ", totalPrice=" + totalPrice + "]";
}
}

View File

@@ -0,0 +1,49 @@
<?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">
<mapper namespace="com.vam.mapper.CartMapper">
<!-- 카트 추가 -->
<insert id="addCart">
insert into vam_cart(memberId, bookId, bookCount)
values(#{memberId}, #{bookId}, #{bookCount})
</insert>
<!-- 카트 삭제 -->
<delete id="deleteCart">
delete from vam_cart where cartId = #{cartId}
</delete>
<!-- 카트 수량 수정 -->
<update id="modifyCount">
update vam_cart set bookCount=#{bookCount} where cartId = #{cartId}
</update>
<!-- 카트 목록 -->
<select id="getCart" resultType="com.vam.model.CartDTO">
select a.cartId, a.memberId, a.bookId, a.bookCount, b.bookName, b.bookPrice, b.bookDiscount
from vam_cart a left outer join vam_book b on a.bookId = b.bookId
where memberId = #{memberId}
</select>
<!-- 카트 확인 -->
<select id="checkCart" resultType="com.vam.model.CartDTO">
select * from vam_cart
where memberId = #{memberId} and bookId = #{bookId}
</select>
</mapper>

View File

@@ -0,0 +1,238 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Welcome BookMall</title>
<link rel="stylesheet" href="/resources/css/goodsDetail.css">
<script
src="https://code.jquery.com/jquery-3.4.1.js"
integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU="
crossorigin="anonymous"></script>
</head>
<body>
<div class="wrapper">
<div class="wrap">
<div class="top_gnb_area">
<ul class="list">
<c:if test = "${member == null}"> <!-- 로그인 x -->
<li >
<a href="/member/login">로그인</a>
</li>
<li>
<a href="/member/join">회원가입</a>
</li>
</c:if>
<c:if test="${member != null }"> <!-- 로그인 o -->
<c:if test="${member.adminCk == 1 }"> <!-- 관리자 계정 -->
<li><a href="/admin/main">관리자 페이지</a></li>
</c:if>
<li>
<a id="gnb_logout_button">로그아웃</a>
</li>
<li>
마이룸
</li>
<li>
장바구니
</li>
</c:if>
<li>
고객센터
</li>
</ul>
</div>
<div class="top_area">
<!-- 로고영역 -->
<div class="logo_area">
<a href="/main"><img src="/resources/img/mLogo.png"></a>
</div>
<div class="search_area">
<div class="search_wrap">
<form id="searchForm" action="/search" method="get">
<div class="search_input">
<select name="type">
<option value="T">책 제목</option>
<option value="A">작가</option>
</select>
<input type="text" name="keyword" value="<c:out value="${pageMaker.cri.keyword}"/>">
<button class='btn search_btn'>검 색</button>
</div>
</form>
</div>
</div>
<div class="login_area">
<!-- 로그인 하지 않은 상태 -->
<c:if test = "${member == null }">
<div class="login_button"><a href="/member/login">로그인</a></div>
<span><a href="/member/join">회원가입</a></span>
</c:if>
<!-- 로그인한 상태 -->
<c:if test="${ member != null }">
<div class="login_success_area">
<span>회원 : ${member.memberName}</span>
<span>충전금액 : <fmt:formatNumber value="${member.money }" pattern="\#,###.##"/></span>
<span>포인트 : <fmt:formatNumber value="${member.point }" pattern="#,###" /></span>
<a href="/member/logout.do">로그아웃</a>
</div>
</c:if>
</div>
<div class="clearfix"></div>
</div>
<div class="content_area">
<div class="line">
</div>
<div class="content_top">
<div class="ct_left_area">
<div class="image_wrap" data-bookid="${goodsInfo.imageList[0].bookId}" data-path="${goodsInfo.imageList[0].uploadPath}" data-uuid="${goodsInfo.imageList[0].uuid}" data-filename="${goodsInfo.imageList[0].fileName}">
<img>
</div>
</div>
<div class="ct_right_area">
<div class="title">
<h1>
${goodsInfo.bookName}
</h1>
</div>
<div class="line">
</div>
<div class="author">
<span>
${goodsInfo.authorName} 지음
</span>
<span>|</span>
<span>
${goodsInfo.publisher}
</span>
<span>|</span>
<span class="publeyear">
${goodsInfo.publeYear}
</span>
</div>
<div class="line">
</div>
<div class="price">
<div class="sale_price">정가 : <fmt:formatNumber value="${goodsInfo.bookPrice}" pattern="#,### 원" /></div>
<div class="discount_price">
판매가 : <span class="discount_price_number"><fmt:formatNumber value="${goodsInfo.bookPrice - (goodsInfo.bookPrice*goodsInfo.bookDiscount)}" pattern="#,### 원" /></span>
[<fmt:formatNumber value="${goodsInfo.bookDiscount*100}" pattern="###" />%
<fmt:formatNumber value="${goodsInfo.bookPrice*goodsInfo.bookDiscount}" pattern="#,### 원" /> 할인]</div>
</div>
<div class="line">
</div>
<div class="button">
<div class="button_quantity">
주문수량
<input type="text" value="1">
<span>
<button>+</button>
<button>-</button>
</span>
</div>
<div class="button_set">
<a class="btn_cart">장바구니 담기</a>
<a class="btn_buy">바로구매</a>
</div>
</div>
</div>
</div>
<div class="line">
</div>
<div class="content_middle">
<div class="book_intro">
${goodsInfo.bookIntro}
</div>
<div class="book_content">
${goodsInfo.bookContents }
</div>
</div>
<div class="line">
</div>
<div class="content_bottom">
리뷰
</div>
</div>
<!-- Footer 영역 -->
<div class="footer_nav">
<div class="footer_nav_container">
<ul>
<li>회사소개</li>
<span class="line">|</span>
<li>이용약관</li>
<span class="line">|</span>
<li>고객센터</li>
<span class="line">|</span>
<li>광고문의</li>
<span class="line">|</span>
<li>채용정보</li>
<span class="line">|</span>
</ul>
</div>
</div> <!-- class="footer_nav" -->
<div class="footer">
<div class="footer_container">
<div class="footer_left">
<img src="/resources/img/Logo.png">
</div>
<div class="footer_right">
(주) VamBook 대표이사 : OOO
<br>
사업자등록번호 : ooo-oo-ooooo
<br>
대표전화 : oooo-oooo(발신자 부담전화)
<br>
<br>
COPYRIGHT(C) <strong>kimvampa.tistory.com</strong> ALL RIGHTS RESERVED.
</div>
<div class="clearfix"></div>
</div>
</div> <!-- class="footer" -->
</div> <!-- class="wrap" -->
</div> <!-- class="wrapper" -->
<script>
$(document).ready(function(){
/* 이미지 삽입 */
const bobj = $(".image_wrap");
if(bobj.data("bookid")){
const uploadPath = bobj.data("path");
const uuid = bobj.data("uuid");
const fileName = bobj.data("filename");
const fileCallPath = encodeURIComponent(uploadPath + "/s_" + uuid + "_" + fileName);
bobj.find("img").attr('src', '/display?fileName=' + fileCallPath);
} else {
bobj.find("img").attr('src', '/resources/img/goodsNoImage.png');
}
/* publeyear */
const year = "${goodsInfo.publeYear}";
let tempYear = year.substr(0,10);
let yearArray = tempYear.split("-")
let publeYear = yearArray[0] + "년 " + yearArray[1] + "월 " + yearArray[2] + "일";
$(".publeyear").html(publeYear);
});
</script>
</body>
</html>

View File

@@ -142,7 +142,9 @@
[${list.cateName}]
</div>
<div class="title">
${list.bookName}
<a href="/goodsDetail/${list.bookId}">
${list.bookName}
</a>
</div>
<div class="author">
<fmt:parseDate var="publeYear" value="${list.publeYear}" pattern="yyyy-MM-dd" />

View File

@@ -0,0 +1,423 @@
@charset "UTF-8";
*{
margin: 0;
padding:0;
}
a{
text-decoration: none;
}
/* 화면 전체 렙 */
.wrapper{
width: 100%;
}
/* content 랩 */
.wrap{
width : 1080px;
margin: auto;
}
/* 홈페이지 기능 네비 */
.top_gnb_area{
width: 100%;
height: 50px;
background-color: #f0f0f1;
position:relative;
}
.top_gnb_area .list{
position: absolute;
top: 0px;
right: 0;
}
.top_gnb_area .list li{
list-style: none;
float : left;
padding: 13px 15px 0 10px;
font-weight: 900;
cursor: pointer;
}
/* 로고, 검색, 로그인 */
.top_area{
width: 100%;
height: 150px;
/* background-color: #f7f0b9; */
}
/* 로고 영역 */
.logo_area{
width: 25%;
height: 100%;
float:left;
}
.logo_area img{
width: 100%;
height: 100%;
}
/* 검색 박스 영역 */
.search_area{
width: 50%;
height: 100%;
float:left;
}
.search_wrap{
width: 100%;
height: 100%;
}
#searchForm{
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.search_input{
display: flex;
height: 30%;
width: 80%;
}
.search_input select{
width: 20%;
text-align: center;
font-size: 15px;
}
.search_input input{
margin-left: 10px;
width: 57%;
font-size: 18px;
padding-left: 2%;
}
.search_btn{
margin-left: 10px;
width: 17%;
border-radius: 14px;
font-size: 17px;
font-weight: 600;
}
/* 로그인 버튼 영역 */
.login_area{
width: 25%;
height: 100%;
display: inline-block;
text-align: center;
}
.login_button{
height: 50%;
background-color: #D4DFE6;
margin-top: 30px;
line-height: 77px;
font-size: 40px;
font-weight: 900;
border-radius: 10px;
cursor: pointer;
}
.login_area>span{
margin-top: 10px;
font-weight: 900;
display: inline-block;
}
.login_button{
height : 50%;
background-color: #D4DFE6;
margin-top:30px;
}
/* 제품 목록 네비 */
.navi_bar_area{
width: 100%;
height: 70px;
background-color: #7696fd;
}
/* 홈페이지 메인 제품 목록 */
.content_area{
width: 100%;
min-height: 1000px;
}
.content_top{
width: 100%;
height: 400px;
}
.content_top:after {
content: "";
clear: both;
display: table;
}
.ct_left_area{
float: left;
width: 30%;
height: 100%;
}
.image_wrap{
height: 80%;
width: 80%;
margin: auto;
top: 10%;
position: relative;
}
.image_wrap img{
max-width: 100%;
height: auto;
display: block;
}
.line{
width: 100%;
border-top:1px solid #c6c6cf;
}
.ct_right_area{
float: left;
width: 70%;
height: 100%;
}
.title{
height: 28%;
font-size: 17px;
line-height: 110px;
color: #3a60df;
padding-left: 3%;
}
.author{
font-size: 16px;
line-height: 50px;
padding-left: 3%;
}
.price{
line-height: 30px;
padding: 2% 0 2% 3%;
}
.discount_price_number{
line-height: 30px;
font-size: 22px;
color: #f84450;
font-weight: bold;
}
.button{
padding: 2% 0 2% 3%;
}
.button_quantity{
margin-bottom: 2%;
}
.button_quantity input{
height: 26px;
width: 40px;
text-align: center;
font-weight: bold;
}
.button_quantity button{
border: 1px solid #aaa;
color: #3a60df;
width: 20px;
height: 20px;
padding: 3px;
background-color: #fff;
font-weight: bold;
font-size: 15px;
line-height: 15px;
}
.btn_cart{
display: inline-block;
width: 140px;
text-align: center;
height: 50px;
line-height: 50px;
background-color: #5e6b9f;
border: 1px solid #5e6b9f;
color: #fff;
margin-right: 2px;
}
.btn_buy{
display: inline-block;
width: 140px;
text-align: center;
height: 50px;
line-height: 50px;
background-color: #7b8ed1;
border: 1px solid #7b8ed1;
color: #fff;
}
.content_middle{
width: 100%;
min-height: 600px;
}
.book_intro{
width: 80%;
margin: auto;
margin-top: 40px;
}
.book_content{
width: 80%;
margin: auto;
margin-top: 40px;
margin-bottom: 40px;
}
.content_bottom{
width: 100%;
min-height: 400px;
background-color: #e7dbdb;
}
/* 로그인 성공 영역 */
.login_success_area{
height: 62%;
width: 80%;
border: 2px solid #7474ad;
border-radius: 15px;
margin: 5% auto;
padding-top: 5%;
}
.login_success_area>a{
font-size: 15px;
font-weight: 900;
display: inline-block;
margin-top: 5px;
background: #e1e5e8;
width: 82px;
height: 22px;
line-height: 22px;
border-radius: 25px;
color: #606267;
}
.login_success_area>span{
display : block;
text-align: left;
margin-left: 10%;
}
/* 검색결과 없음 */
.table_empty{
height: 50px;
text-align: center;
margin: 200px 0 215px 0px;
font-size: 25px;
}
/* 필터정보 */
.search_filter {
width: 85%;
margin: auto;
margin-top: 30px;
margin-bottom: 50px;
}
.filter_button_wrap {
width: 100%;
}
.filter_button_wrap button {
width: 50%;
}
.filter_button{
background-color: #04AA6D;
border: 1px solid green;
color: white;
padding: 10px 24px;
cursor: pointer;
float: left;
}
.filter_button_wrap:after {
content: "";
clear: both;
display: table;
}
.filter_button_wrap button:not(:last-child) {
border-right: none;
}
.filter_button:hover {
background-color: #3e8e41;
}
.filter_active{
background-color: #045d3c;
}
.filter_content{
padding:20px 50px 20px 50px;
border: 1px solid gray;
}
.filter_content a:not(:first-child){
margin-left: 10px;
}
.filter_a{
display: block;
}
.filter_b{
display: none;
}
/* footer navai 영역 */
.footer_nav{
width:100%;
height:50px;
}
.footer_nav_container{
width: 100%;
height: 100%;
background-color:#8EC0E4;
}
.footer_nav_container>ul{
font-weight : bold;
float:left;
list-style:none;
position:relative;
padding-top:10px;
line-height: 27px;
font-family: dotum;
margin-left: 10px;
}
.footer_nav_container>ul>li{
display:inline;
width: 45px;
height: 19px;
padding: 10px 9px 0 10px;
}
.footer_nav_container>ul>span{
margin: 0 4px;
}
/* footer 영역 */
.footer{
width:100%;
height:130px;
background-color:#D4DFE6;
padding-bottom : 50px;
}
.footer_container{
width: 100%;
height: 100%;
margin: auto;
}
.footer_left>img {
width: 150%;
height: 130px;
margin-left: -20px;
margin-top: -12px;
}
.footer_left{
float :left;
width: 170px;
margin-left: 20px;
margin-top : 30px;
}
.footer_right{
float :left;
width: 680px;
margin-left: 70px;
margin-top : 30px;
}
/* float 속성 해제 */
.clearfix{
clear: both;
}

View File

@@ -0,0 +1,107 @@
package com.vam.mapper;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.vam.model.CartDTO;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("file:src/main/webapp/WEB-INF/spring/root-context.xml")
public class CartMapperTests {
@Autowired
private CartMapper mapper;
/*카트 등록*/
/*
@Test
public void addCart() {
String memberId = "admin";
int bookId = 65;
int count = 2;
CartDTO cart = new CartDTO();
cart.setMemberId(memberId);
cart.setBookId(bookId);
cart.setBookCount(count);
int result = 0;
try {
result = mapper.addCart(cart);
} catch (Exception e) {
System.out.println("에러 발생");
}
System.out.println("결과 : " + result);
}
*/
/* 카트 삭제 */
/*
@Test
public void deleteCartTest() {
int cartId = 1;
mapper.deleteCart(cartId);
}
*/
/* 카트 수량 수정 */
/*
@Test
public void modifyCartTest() {
int cartId = 3;
int count = 5;
CartDTO cart = new CartDTO();
cart.setCartId(cartId);
cart.setBookCount(count);
mapper.modifyCount(cart);
}
*/
/*
@Test
public void getCartTest() {
String memberId = "admin";
List<CartDTO> list = mapper.getCart(memberId);
for(CartDTO cart : list) {
System.out.println(cart);
cart.initSaleTotal();
System.out.println("init cart : " + cart);
}
}
*/
/* 카트 확인 */
/*
@Test
public void checkCartTest() {
String memberId = "admin";
int bookId = 71;
CartDTO cart = new CartDTO();
cart.setMemberId(memberId);
cart.setBookId(bookId);
CartDTO resutlCart = mapper.checkCart(cart);
System.out.println("결과 : " + resutlCart);
}
*/
}

View File

@@ -0,0 +1,49 @@
<?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">
<mapper namespace="com.vam.mapper.CartMapper">
<!-- 카트 추가 -->
<insert id="addCart">
insert into vam_cart(memberId, bookId, bookCount)
values(#{memberId}, #{bookId}, #{bookCount})
</insert>
<!-- 카트 삭제 -->
<delete id="deleteCart">
delete from vam_cart where cartId = #{cartId}
</delete>
<!-- 카트 수량 수정 -->
<update id="modifyCount">
update vam_cart set bookCount=#{bookCount} where cartId = #{cartId}
</update>
<!-- 카트 목록 -->
<select id="getCart" resultType="com.vam.model.CartDTO">
select a.cartId, a.memberId, a.bookId, a.bookCount, b.bookName, b.bookPrice, b.bookDiscount
from vam_cart a left outer join vam_book b on a.bookId = b.bookId
where memberId = #{memberId}
</select>
<!-- 카트 확인 -->
<select id="checkCart" resultType="com.vam.model.CartDTO">
select * from vam_cart
where memberId = #{memberId} and bookId = #{bookId}
</select>
</mapper>

View File

@@ -1,5 +1,5 @@
#Generated by Maven Integration for Eclipse
#Wed Nov 10 13:50:38 KST 2021
#Sat Nov 13 22:18:14 KST 2021
m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa
m2e.projectName=VamPa
groupId=com.vam

View File

@@ -0,0 +1,24 @@
package com.vam.mapper;
import java.util.List;
import com.vam.model.CartDTO;
public interface CartMapper {
/* 카트 추가 */
public int addCart(CartDTO cart);
/* 카트 삭제 */
public int deleteCart(int cartId);
/* 카트 수량 수정 */
public int modifyCount(CartDTO cart);
/* 카트 목록 */
public List<CartDTO> getCart(String memberId);
/* 카트 확인 */
public CartDTO checkCart(CartDTO cart);
}

View File

@@ -0,0 +1,102 @@
package com.vam.model;
public class CartDTO {
private int cartId;
private String memberId;
private int bookId;
private int bookCount;
//book
private String bookName;
private int bookPrice;
private double bookDiscount;
// 추가
private int salePrice;
private int totalPrice;
public int getCartId() {
return cartId;
}
public void setCartId(int cartId) {
this.cartId = cartId;
}
public String getMemberId() {
return memberId;
}
public void setMemberId(String memberId) {
this.memberId = memberId;
}
public int getBookId() {
return bookId;
}
public void setBookId(int bookId) {
this.bookId = bookId;
}
public int getBookCount() {
return bookCount;
}
public void setBookCount(int bookCount) {
this.bookCount = bookCount;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public int getBookPrice() {
return bookPrice;
}
public void setBookPrice(int bookPrice) {
this.bookPrice = bookPrice;
}
public double getBookDiscount() {
return bookDiscount;
}
public void setBookDiscount(double bookDiscount) {
this.bookDiscount = bookDiscount;
}
public int getSalePrice() {
return salePrice;
}
public int getTotalPrice() {
return totalPrice;
}
public void initSaleTotal() {
this.salePrice = (int) (this.bookPrice * (1-this.bookDiscount));
this.totalPrice = this.salePrice*this.bookCount;
}
@Override
public String toString() {
return "CartDTO [cartId=" + cartId + ", memberId=" + memberId + ", bookId=" + bookId + ", bookCount="
+ bookCount + ", bookName=" + bookName + ", bookPrice=" + bookPrice + ", bookDiscount=" + bookDiscount
+ ", salePrice=" + salePrice + ", totalPrice=" + totalPrice + "]";
}
}

View File

@@ -0,0 +1,49 @@
<?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">
<mapper namespace="com.vam.mapper.CartMapper">
<!-- 카트 추가 -->
<insert id="addCart">
insert into vam_cart(memberId, bookId, bookCount)
values(#{memberId}, #{bookId}, #{bookCount})
</insert>
<!-- 카트 삭제 -->
<delete id="deleteCart">
delete from vam_cart where cartId = #{cartId}
</delete>
<!-- 카트 수량 수정 -->
<update id="modifyCount">
update vam_cart set bookCount=#{bookCount} where cartId = #{cartId}
</update>
<!-- 카트 목록 -->
<select id="getCart" resultType="com.vam.model.CartDTO">
select a.cartId, a.memberId, a.bookId, a.bookCount, b.bookName, b.bookPrice, b.bookDiscount
from vam_cart a left outer join vam_book b on a.bookId = b.bookId
where memberId = #{memberId}
</select>
<!-- 카트 확인 -->
<select id="checkCart" resultType="com.vam.model.CartDTO">
select * from vam_cart
where memberId = #{memberId} and bookId = #{bookId}
</select>
</mapper>

View File

@@ -0,0 +1,102 @@
package com.vam.mapper;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("file:src/main/webapp/WEB-INF/spring/root-context.xml")
public class CartMapperTests {
@Autowired
private CartMapper mapper;
/*카트 등록*/
/*
@Test
public void addCart() {
String memberId = "admin";
int bookId = 65;
int count = 2;
CartDTO cart = new CartDTO();
cart.setMemberId(memberId);
cart.setBookId(bookId);
cart.setBookCount(count);
int result = 0;
try {
result = mapper.addCart(cart);
} catch (Exception e) {
System.out.println("에러 발생");
}
System.out.println("결과 : " + result);
}
*/
/* 카트 삭제 */
/*
@Test
public void deleteCartTest() {
int cartId = 1;
mapper.deleteCart(cartId);
}
*/
/* 카트 수량 수정 */
/*
@Test
public void modifyCartTest() {
int cartId = 3;
int count = 5;
CartDTO cart = new CartDTO();
cart.setCartId(cartId);
cart.setBookCount(count);
mapper.modifyCount(cart);
}
*/
/*
@Test
public void getCartTest() {
String memberId = "admin";
List<CartDTO> list = mapper.getCart(memberId);
for(CartDTO cart : list) {
System.out.println(cart);
cart.initSaleTotal();
System.out.println("init cart : " + cart);
}
}
*/
/* 카트 확인 */
/*
@Test
public void checkCartTest() {
String memberId = "admin";
int bookId = 71;
CartDTO cart = new CartDTO();
cart.setMemberId(memberId);
cart.setBookId(bookId);
CartDTO resutlCart = mapper.checkCart(cart);
System.out.println("결과 : " + resutlCart);
}
*/
}

View File

@@ -0,0 +1,49 @@
<?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">
<mapper namespace="com.vam.mapper.CartMapper">
<!-- 카트 추가 -->
<insert id="addCart">
insert into vam_cart(memberId, bookId, bookCount)
values(#{memberId}, #{bookId}, #{bookCount})
</insert>
<!-- 카트 삭제 -->
<delete id="deleteCart">
delete from vam_cart where cartId = #{cartId}
</delete>
<!-- 카트 수량 수정 -->
<update id="modifyCount">
update vam_cart set bookCount=#{bookCount} where cartId = #{cartId}
</update>
<!-- 카트 목록 -->
<select id="getCart" resultType="com.vam.model.CartDTO">
select a.cartId, a.memberId, a.bookId, a.bookCount, b.bookName, b.bookPrice, b.bookDiscount
from vam_cart a left outer join vam_book b on a.bookId = b.bookId
where memberId = #{memberId}
</select>
<!-- 카트 확인 -->
<select id="checkCart" resultType="com.vam.model.CartDTO">
select * from vam_cart
where memberId = #{memberId} and bookId = #{bookId}
</select>
</mapper>

View File

@@ -1,5 +1,5 @@
#Generated by Maven Integration for Eclipse
#Wed Nov 10 13:48:51 KST 2021
#Sat Nov 13 22:18:15 KST 2021
m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa_MySQL
m2e.projectName=VamPa_MySQL
groupId=com.vam