[Spring][쇼핑몰 프로젝트][37] 장바구니 기능(장바구니 페이지) -1
https://kimvampa.tistory.com/265
This commit is contained in:
@@ -5,6 +5,9 @@ import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@@ -44,4 +47,13 @@ public class CartController {
|
||||
return result + "";
|
||||
}
|
||||
|
||||
/* 장바구니 페이지 이동 */
|
||||
@GetMapping("/cart/{memberId}")
|
||||
public String cartPageGET(@PathVariable("memberId") String memberId, Model model) {
|
||||
|
||||
model.addAttribute("cartInfo", cartService.getCartList(memberId));
|
||||
|
||||
return "/cart";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,10 @@ public class CartDTO {
|
||||
|
||||
private int totalPrice;
|
||||
|
||||
private int point;
|
||||
|
||||
private int totalPoint;
|
||||
|
||||
public int getCartId() {
|
||||
return cartId;
|
||||
}
|
||||
@@ -87,19 +91,32 @@ public class CartDTO {
|
||||
return totalPrice;
|
||||
}
|
||||
|
||||
public int getPoint() {
|
||||
return point;
|
||||
}
|
||||
|
||||
public int getTotalPoint() {
|
||||
return totalPoint;
|
||||
}
|
||||
|
||||
public void initSaleTotal() {
|
||||
this.salePrice = (int) (this.bookPrice * (1-this.bookDiscount));
|
||||
this.totalPrice = this.salePrice*this.bookCount;
|
||||
this.point = (int)(Math.floor(this.salePrice*0.05));
|
||||
this.totalPoint =this.point * 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 + "]";
|
||||
+ ", salePrice=" + salePrice + ", totalPrice=" + totalPrice + ", point=" + point + ", totalPoint="
|
||||
+ totalPoint + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.vam.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.vam.model.CartDTO;
|
||||
|
||||
public interface CartService {
|
||||
@@ -7,4 +9,7 @@ public interface CartService {
|
||||
/* 장바구니 추가 */
|
||||
public int addCart(CartDTO cart);
|
||||
|
||||
/* 장바구니 정보 리스트 */
|
||||
public List<CartDTO> getCartList(String memberId);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.vam.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -30,5 +32,18 @@ public class CartServiceImpl implements CartService {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CartDTO> getCartList(String memberId) {
|
||||
|
||||
List<CartDTO> cart = cartMapper.getCart(memberId);
|
||||
|
||||
for(CartDTO dto : cart) {
|
||||
dto.initSaleTotal();
|
||||
}
|
||||
|
||||
return cart;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
12
VamPa/src/main/webapp/WEB-INF/views/cart.jsp
Normal file
12
VamPa/src/main/webapp/WEB-INF/views/cart.jsp
Normal file
@@ -0,0 +1,12 @@
|
||||
<%@ 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>
|
||||
${cartInfo}
|
||||
</body>
|
||||
</html>
|
||||
@@ -38,7 +38,7 @@
|
||||
마이룸
|
||||
</li>
|
||||
<li>
|
||||
장바구니
|
||||
<a href="/cart/${member.memberId}">장바구니</a>
|
||||
</li>
|
||||
</c:if>
|
||||
<li>
|
||||
@@ -123,7 +123,11 @@
|
||||
<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>
|
||||
<fmt:formatNumber value="${goodsInfo.bookPrice*goodsInfo.bookDiscount}" pattern="#,### 원" /> 할인]
|
||||
</div>
|
||||
<div>
|
||||
적립 포인트 : <span class="point_span"></span>원
|
||||
</div>
|
||||
</div>
|
||||
<div class="line">
|
||||
</div>
|
||||
@@ -231,7 +235,13 @@ $(document).ready(function(){
|
||||
|
||||
$(".publeyear").html(publeYear);
|
||||
|
||||
});
|
||||
/* 포인트 삽입 */
|
||||
let salePrice = "${goodsInfo.bookPrice - (goodsInfo.bookPrice*goodsInfo.bookDiscount)}"
|
||||
let point = salePrice*0.05;
|
||||
point = Math.floor(point);
|
||||
$(".point_span").text(point);
|
||||
|
||||
}); //$(document).ready(function(){
|
||||
|
||||
|
||||
// 수량 버튼 조작
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
마이룸
|
||||
</li>
|
||||
<li>
|
||||
장바구니
|
||||
<a href="/cart/${member.memberId}">장바구니</a>
|
||||
</li>
|
||||
</c:if>
|
||||
<li>
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
마이룸
|
||||
</li>
|
||||
<li>
|
||||
장바구니
|
||||
<a href="/cart/${member.memberId}">장바구니</a>
|
||||
</li>
|
||||
</c:if>
|
||||
<li>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#Generated by Maven Integration for Eclipse
|
||||
#Sat Nov 13 22:18:14 KST 2021
|
||||
#Tue Nov 23 14:20:08 KST 2021
|
||||
m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa
|
||||
m2e.projectName=VamPa
|
||||
groupId=com.vam
|
||||
|
||||
@@ -5,6 +5,9 @@ import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@@ -44,4 +47,13 @@ public class CartController {
|
||||
return result + "";
|
||||
}
|
||||
|
||||
/* 장바구니 페이지 이동 */
|
||||
@GetMapping("/cart/{memberId}")
|
||||
public String cartPageGET(@PathVariable("memberId") String memberId, Model model) {
|
||||
|
||||
model.addAttribute("cartInfo", cartService.getCartList(memberId));
|
||||
|
||||
return "/cart";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,10 @@ public class CartDTO {
|
||||
|
||||
private int totalPrice;
|
||||
|
||||
private int point;
|
||||
|
||||
private int totalPoint;
|
||||
|
||||
public int getCartId() {
|
||||
return cartId;
|
||||
}
|
||||
@@ -87,16 +91,27 @@ public class CartDTO {
|
||||
return totalPrice;
|
||||
}
|
||||
|
||||
public int getPoint() {
|
||||
return point;
|
||||
}
|
||||
|
||||
public int getTotalPoint() {
|
||||
return totalPoint;
|
||||
}
|
||||
|
||||
public void initSaleTotal() {
|
||||
this.salePrice = (int) (this.bookPrice * (1-this.bookDiscount));
|
||||
this.totalPrice = this.salePrice*this.bookCount;
|
||||
this.point = (int)(Math.floor(this.salePrice*0.05));
|
||||
this.totalPoint =this.point * 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 + "]";
|
||||
+ ", salePrice=" + salePrice + ", totalPrice=" + totalPrice + ", point=" + point + ", totalPoint="
|
||||
+ totalPoint + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.vam.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.vam.model.CartDTO;
|
||||
|
||||
public interface CartService {
|
||||
@@ -7,4 +9,7 @@ public interface CartService {
|
||||
/* 장바구니 추가 */
|
||||
public int addCart(CartDTO cart);
|
||||
|
||||
/* 장바구니 정보 리스트 */
|
||||
public List<CartDTO> getCartList(String memberId);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.vam.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -30,4 +32,17 @@ public class CartServiceImpl implements CartService {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CartDTO> getCartList(String memberId) {
|
||||
|
||||
List<CartDTO> cart = cartMapper.getCart(memberId);
|
||||
|
||||
for(CartDTO dto : cart) {
|
||||
dto.initSaleTotal();
|
||||
}
|
||||
|
||||
return cart;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
12
VamPa_MySQL/src/main/webapp/WEB-INF/views/cart.jsp
Normal file
12
VamPa_MySQL/src/main/webapp/WEB-INF/views/cart.jsp
Normal file
@@ -0,0 +1,12 @@
|
||||
<%@ 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>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -38,7 +38,7 @@
|
||||
마이룸
|
||||
</li>
|
||||
<li>
|
||||
장바구니
|
||||
<a href="/cart/${member.memberId}">장바구니</a>
|
||||
</li>
|
||||
</c:if>
|
||||
<li>
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
마이룸
|
||||
</li>
|
||||
<li>
|
||||
장바구니
|
||||
<a href="/cart/${member.memberId}">장바구니</a>
|
||||
</li>
|
||||
</c:if>
|
||||
<li>
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
마이룸
|
||||
</li>
|
||||
<li>
|
||||
장바구니
|
||||
<a href="/cart/${member.memberId}">장바구니</a>
|
||||
</li>
|
||||
</c:if>
|
||||
<li>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#Generated by Maven Integration for Eclipse
|
||||
#Sat Nov 13 22:18:15 KST 2021
|
||||
#Tue Nov 23 14:20:08 KST 2021
|
||||
m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project2\\VamPa_MySQL
|
||||
m2e.projectName=VamPa_MySQL
|
||||
groupId=com.vam
|
||||
|
||||
Reference in New Issue
Block a user