[Spring][쇼핑몰 프로젝트][39] 장바구니 기능(장바구니 삭제)
https://kimvampa.tistory.com/270
This commit is contained in:
@@ -66,4 +66,14 @@ public class CartController {
|
||||
|
||||
}
|
||||
|
||||
/* 장바구니 수량 수정 */
|
||||
@PostMapping("/cart/delete")
|
||||
public String deleteCartPOST(CartDTO cart) {
|
||||
|
||||
cartService.deleteCart(cart.getCartId());
|
||||
|
||||
return "redirect:/cart/" + cart.getMemberId();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,5 +14,8 @@ public interface CartService {
|
||||
|
||||
/* 카트 수량 수정 */
|
||||
public int modifyCount(CartDTO cart);
|
||||
|
||||
/* 카트 삭제 */
|
||||
public int deleteCart(int cartId);
|
||||
|
||||
}
|
||||
|
||||
@@ -65,5 +65,11 @@ public class CartServiceImpl implements CartService {
|
||||
return cartMapper.modifyCount(cart);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteCart(int cartId) {
|
||||
|
||||
return cartMapper.deleteCart(cartId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -151,7 +151,9 @@
|
||||
<td class="td_width_4 table_text_align_center">
|
||||
<fmt:formatNumber value="${ci.salePrice * ci.bookCount}" pattern="#,### 원" />
|
||||
</td>
|
||||
<td class="td_width_4 table_text_align_center delete_btn"><button>삭제</button></td>
|
||||
<td class="td_width_4 table_text_align_center">
|
||||
<button class="delete_btn" data-cartid="${ci.cartId}">삭제</button>
|
||||
</td>
|
||||
</tr>
|
||||
</c:forEach>
|
||||
</tbody>
|
||||
@@ -240,7 +242,13 @@
|
||||
<input type="hidden" name="cartId" class="update_cartId">
|
||||
<input type="hidden" name="bookCount" class="update_bookCount">
|
||||
<input type="hidden" name="memberId" value="${member.memberId}">
|
||||
</form>
|
||||
</form>
|
||||
|
||||
<!-- 삭제 form -->
|
||||
<form action="/cart/delete" method="post" class="quantity_delete_form">
|
||||
<input type="hidden" name="cartId" class="delete_cartId">
|
||||
<input type="hidden" name="memberId" value="${member.memberId}">
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -412,6 +420,15 @@ $(".quantity_modify_btn").on("click", function(){
|
||||
|
||||
});
|
||||
|
||||
/* 장바구니 삭제 버튼 */
|
||||
$(".delete_btn").on("click", function(e){
|
||||
e.preventDefault();
|
||||
const cartId = $(this).data("cartid");
|
||||
$(".delete_cartId").val(cartId);
|
||||
$(".quantity_delete_form").submit();
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
@@ -66,4 +66,14 @@ public class CartController {
|
||||
|
||||
}
|
||||
|
||||
/* 장바구니 수량 수정 */
|
||||
@PostMapping("/cart/delete")
|
||||
public String deleteCartPOST(CartDTO cart) {
|
||||
|
||||
cartService.deleteCart(cart.getCartId());
|
||||
|
||||
return "redirect:/cart/" + cart.getMemberId();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@ public interface CartService {
|
||||
public List<CartDTO> getCartList(String memberId);
|
||||
|
||||
/* 카트 수량 수정 */
|
||||
public int modifyCount(CartDTO cart);
|
||||
public int modifyCount(CartDTO cart);
|
||||
|
||||
/* 카트 삭제 */
|
||||
public int deleteCart(int cartId);
|
||||
|
||||
}
|
||||
|
||||
@@ -65,4 +65,10 @@ public class CartServiceImpl implements CartService {
|
||||
return cartMapper.modifyCount(cart);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteCart(int cartId) {
|
||||
|
||||
return cartMapper.deleteCart(cartId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -151,7 +151,9 @@
|
||||
<td class="td_width_4 table_text_align_center">
|
||||
<fmt:formatNumber value="${ci.salePrice * ci.bookCount}" pattern="#,### 원" />
|
||||
</td>
|
||||
<td class="td_width_4 table_text_align_center delete_btn"><button>삭제</button></td>
|
||||
<td class="td_width_4 table_text_align_center">
|
||||
<button class="delete_btn" data-cartid="${ci.cartId}">삭제</button>
|
||||
</td>
|
||||
</tr>
|
||||
</c:forEach>
|
||||
</tbody>
|
||||
@@ -240,7 +242,13 @@
|
||||
<input type="hidden" name="cartId" class="update_cartId">
|
||||
<input type="hidden" name="bookCount" class="update_bookCount">
|
||||
<input type="hidden" name="memberId" value="${member.memberId}">
|
||||
</form>
|
||||
</form>
|
||||
|
||||
<!-- 삭제 form -->
|
||||
<form action="/cart/delete" method="post" class="quantity_delete_form">
|
||||
<input type="hidden" name="cartId" class="delete_cartId">
|
||||
<input type="hidden" name="memberId" value="${member.memberId}">
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -412,6 +420,15 @@ $(".quantity_modify_btn").on("click", function(){
|
||||
|
||||
});
|
||||
|
||||
/* 장바구니 삭제 버튼 */
|
||||
$(".delete_btn").on("click", function(e){
|
||||
e.preventDefault();
|
||||
const cartId = $(this).data("cartid");
|
||||
$(".delete_cartId").val(cartId);
|
||||
$(".quantity_delete_form").submit();
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user