From 96949a54d551b313478725de24824b06ad237fb6 Mon Sep 17 00:00:00 2001 From: SeoJin Kim Date: Wed, 24 Nov 2021 02:15:48 +0900 Subject: [PATCH] =?UTF-8?q?[Spring][=EC=87=BC=ED=95=91=EB=AA=B0=20?= =?UTF-8?q?=ED=94=84=EB=A1=9C=EC=A0=9D=ED=8A=B8][37]=20=EC=9E=A5=EB=B0=94?= =?UTF-8?q?=EA=B5=AC=EB=8B=88=20=EA=B8=B0=EB=8A=A5(=EC=9E=A5=EB=B0=94?= =?UTF-8?q?=EA=B5=AC=EB=8B=88=20=ED=8E=98=EC=9D=B4=EC=A7=80)=20-1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://kimvampa.tistory.com/265 --- .../com/vam/controller/CartController.java | 12 +++++++++ .../src/main/java/com/vam/model/CartDTO.java | 25 ++++++++++++++++--- .../java/com/vam/service/CartService.java | 5 ++++ .../java/com/vam/service/CartServiceImpl.java | 15 +++++++++++ VamPa/src/main/webapp/WEB-INF/views/cart.jsp | 12 +++++++++ .../main/webapp/WEB-INF/views/goodsDetail.jsp | 16 +++++++++--- VamPa/src/main/webapp/WEB-INF/views/main.jsp | 2 +- .../src/main/webapp/WEB-INF/views/search.jsp | 2 +- .../maven/com.vam/controller/pom.properties | 2 +- .../com/vam/controller/CartController.java | 12 +++++++++ .../src/main/java/com/vam/model/CartDTO.java | 21 +++++++++++++--- .../java/com/vam/service/CartService.java | 7 +++++- .../java/com/vam/service/CartServiceImpl.java | 15 +++++++++++ .../src/main/webapp/WEB-INF/views/cart.jsp | 12 +++++++++ .../main/webapp/WEB-INF/views/goodsDetail.jsp | 2 +- .../src/main/webapp/WEB-INF/views/main.jsp | 2 +- .../src/main/webapp/WEB-INF/views/search.jsp | 2 +- .../maven/com.vam/controller/pom.properties | 2 +- 18 files changed, 148 insertions(+), 18 deletions(-) create mode 100644 VamPa/src/main/webapp/WEB-INF/views/cart.jsp create mode 100644 VamPa_MySQL/src/main/webapp/WEB-INF/views/cart.jsp diff --git a/VamPa/src/main/java/com/vam/controller/CartController.java b/VamPa/src/main/java/com/vam/controller/CartController.java index 592cc18..6202468 100644 --- a/VamPa/src/main/java/com/vam/controller/CartController.java +++ b/VamPa/src/main/java/com/vam/controller/CartController.java @@ -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"; + } + } diff --git a/VamPa/src/main/java/com/vam/model/CartDTO.java b/VamPa/src/main/java/com/vam/model/CartDTO.java index ab99770..0f506e8 100644 --- a/VamPa/src/main/java/com/vam/model/CartDTO.java +++ b/VamPa/src/main/java/com/vam/model/CartDTO.java @@ -22,6 +22,10 @@ public class CartDTO { private int salePrice; private int totalPrice; + + private int point; + + private int totalPoint; public int getCartId() { return cartId; @@ -85,19 +89,32 @@ public class CartDTO { public int getTotalPrice() { 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 + "]"; + } + + diff --git a/VamPa/src/main/java/com/vam/service/CartService.java b/VamPa/src/main/java/com/vam/service/CartService.java index 7a685a1..6b05ac4 100644 --- a/VamPa/src/main/java/com/vam/service/CartService.java +++ b/VamPa/src/main/java/com/vam/service/CartService.java @@ -1,10 +1,15 @@ package com.vam.service; +import java.util.List; + import com.vam.model.CartDTO; public interface CartService { /* 장바구니 추가 */ public int addCart(CartDTO cart); + + /* 장바구니 정보 리스트 */ + public List getCartList(String memberId); } diff --git a/VamPa/src/main/java/com/vam/service/CartServiceImpl.java b/VamPa/src/main/java/com/vam/service/CartServiceImpl.java index 28e6fe3..19f3418 100644 --- a/VamPa/src/main/java/com/vam/service/CartServiceImpl.java +++ b/VamPa/src/main/java/com/vam/service/CartServiceImpl.java @@ -1,5 +1,7 @@ package com.vam.service; +import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -29,6 +31,19 @@ public class CartServiceImpl implements CartService { } } + + @Override + public List getCartList(String memberId) { + + List cart = cartMapper.getCart(memberId); + + for(CartDTO dto : cart) { + dto.initSaleTotal(); + } + + return cart; + + } } diff --git a/VamPa/src/main/webapp/WEB-INF/views/cart.jsp b/VamPa/src/main/webapp/WEB-INF/views/cart.jsp new file mode 100644 index 0000000..bf8d04a --- /dev/null +++ b/VamPa/src/main/webapp/WEB-INF/views/cart.jsp @@ -0,0 +1,12 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + + + +Insert title here + + + ${cartInfo} + + \ No newline at end of file diff --git a/VamPa/src/main/webapp/WEB-INF/views/goodsDetail.jsp b/VamPa/src/main/webapp/WEB-INF/views/goodsDetail.jsp index a6b01cc..bfe7838 100644 --- a/VamPa/src/main/webapp/WEB-INF/views/goodsDetail.jsp +++ b/VamPa/src/main/webapp/WEB-INF/views/goodsDetail.jsp @@ -38,7 +38,7 @@ 마이룸
  • - 장바구니 + 장바구니
  • @@ -123,7 +123,11 @@
    판매가 : [% - 할인]
    + 할인] + +
    + 적립 포인트 : 원 +
    @@ -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(){ // 수량 버튼 조작 diff --git a/VamPa/src/main/webapp/WEB-INF/views/main.jsp b/VamPa/src/main/webapp/WEB-INF/views/main.jsp index 4ded09d..b927d23 100644 --- a/VamPa/src/main/webapp/WEB-INF/views/main.jsp +++ b/VamPa/src/main/webapp/WEB-INF/views/main.jsp @@ -38,7 +38,7 @@ 마이룸
  • - 장바구니 + 장바구니
  • diff --git a/VamPa/src/main/webapp/WEB-INF/views/search.jsp b/VamPa/src/main/webapp/WEB-INF/views/search.jsp index f51004f..f7d12cd 100644 --- a/VamPa/src/main/webapp/WEB-INF/views/search.jsp +++ b/VamPa/src/main/webapp/WEB-INF/views/search.jsp @@ -38,7 +38,7 @@ 마이룸
  • - 장바구니 + 장바구니
  • diff --git a/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties b/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties index ffd76fc..e49b31c 100644 --- a/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties +++ b/VamPa/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties @@ -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 diff --git a/VamPa_MySQL/src/main/java/com/vam/controller/CartController.java b/VamPa_MySQL/src/main/java/com/vam/controller/CartController.java index a549dc8..54ff1e8 100644 --- a/VamPa_MySQL/src/main/java/com/vam/controller/CartController.java +++ b/VamPa_MySQL/src/main/java/com/vam/controller/CartController.java @@ -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; @@ -42,6 +45,15 @@ public class CartController { int result = cartService.addCart(cart); return result + ""; + } + + /* 장바구니 페이지 이동 */ + @GetMapping("/cart/{memberId}") + public String cartPageGET(@PathVariable("memberId") String memberId, Model model) { + + model.addAttribute("cartInfo", cartService.getCartList(memberId)); + + return "/cart"; } } diff --git a/VamPa_MySQL/src/main/java/com/vam/model/CartDTO.java b/VamPa_MySQL/src/main/java/com/vam/model/CartDTO.java index 55e6490..11fbf54 100644 --- a/VamPa_MySQL/src/main/java/com/vam/model/CartDTO.java +++ b/VamPa_MySQL/src/main/java/com/vam/model/CartDTO.java @@ -22,6 +22,10 @@ public class CartDTO { private int salePrice; 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 + "]"; + } } diff --git a/VamPa_MySQL/src/main/java/com/vam/service/CartService.java b/VamPa_MySQL/src/main/java/com/vam/service/CartService.java index 688d9ce..146ef51 100644 --- a/VamPa_MySQL/src/main/java/com/vam/service/CartService.java +++ b/VamPa_MySQL/src/main/java/com/vam/service/CartService.java @@ -1,10 +1,15 @@ package com.vam.service; +import java.util.List; + import com.vam.model.CartDTO; public interface CartService { /* 장바구니 추가 */ - public int addCart(CartDTO cart); + public int addCart(CartDTO cart); + + /* 장바구니 정보 리스트 */ + public List getCartList(String memberId); } diff --git a/VamPa_MySQL/src/main/java/com/vam/service/CartServiceImpl.java b/VamPa_MySQL/src/main/java/com/vam/service/CartServiceImpl.java index 61269d6..464d98c 100644 --- a/VamPa_MySQL/src/main/java/com/vam/service/CartServiceImpl.java +++ b/VamPa_MySQL/src/main/java/com/vam/service/CartServiceImpl.java @@ -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 getCartList(String memberId) { + + List cart = cartMapper.getCart(memberId); + + for(CartDTO dto : cart) { + dto.initSaleTotal(); + } + + return cart; + + } + } diff --git a/VamPa_MySQL/src/main/webapp/WEB-INF/views/cart.jsp b/VamPa_MySQL/src/main/webapp/WEB-INF/views/cart.jsp new file mode 100644 index 0000000..ce046b5 --- /dev/null +++ b/VamPa_MySQL/src/main/webapp/WEB-INF/views/cart.jsp @@ -0,0 +1,12 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + + + +Insert title here + + + + + \ No newline at end of file diff --git a/VamPa_MySQL/src/main/webapp/WEB-INF/views/goodsDetail.jsp b/VamPa_MySQL/src/main/webapp/WEB-INF/views/goodsDetail.jsp index a6b01cc..c0394e0 100644 --- a/VamPa_MySQL/src/main/webapp/WEB-INF/views/goodsDetail.jsp +++ b/VamPa_MySQL/src/main/webapp/WEB-INF/views/goodsDetail.jsp @@ -38,7 +38,7 @@ 마이룸
  • - 장바구니 + 장바구니
  • diff --git a/VamPa_MySQL/src/main/webapp/WEB-INF/views/main.jsp b/VamPa_MySQL/src/main/webapp/WEB-INF/views/main.jsp index abeb2ff..8dd0f47 100644 --- a/VamPa_MySQL/src/main/webapp/WEB-INF/views/main.jsp +++ b/VamPa_MySQL/src/main/webapp/WEB-INF/views/main.jsp @@ -38,7 +38,7 @@ 마이룸
  • - 장바구니 + 장바구니
  • diff --git a/VamPa_MySQL/src/main/webapp/WEB-INF/views/search.jsp b/VamPa_MySQL/src/main/webapp/WEB-INF/views/search.jsp index 0962ec5..cbac800 100644 --- a/VamPa_MySQL/src/main/webapp/WEB-INF/views/search.jsp +++ b/VamPa_MySQL/src/main/webapp/WEB-INF/views/search.jsp @@ -38,7 +38,7 @@ 마이룸
  • - 장바구니 + 장바구니
  • diff --git a/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties b/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties index e81f609..6416476 100644 --- a/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties +++ b/VamPa_MySQL/target/m2e-wtp/web-resources/META-INF/maven/com.vam/controller/pom.properties @@ -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