1
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package edu.neu.neumall.controller;
|
||||
|
||||
import edu.neu.neumall.entity.Product;
|
||||
import edu.neu.neumall.entity.ShoppingCart;
|
||||
import edu.neu.neumall.entity.User;
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@@ -9,6 +10,7 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/cart")
|
||||
@@ -17,13 +19,11 @@ public class ShoppingCartController {
|
||||
public String shoppingCartPage(@AuthenticationPrincipal User user, Model model) {
|
||||
ArrayList<Product> products = new ArrayList<>();
|
||||
var shoppingCartItems = user.getShoppingCart();
|
||||
if (shoppingCartItems != null) {
|
||||
for (var item : shoppingCartItems) {
|
||||
|
||||
products.add(item.getProduct());
|
||||
}
|
||||
if (shoppingCartItems == null) {
|
||||
shoppingCartItems = new HashSet<ShoppingCart>();
|
||||
}
|
||||
model.addAttribute("productList", products);
|
||||
model.addAttribute("productlist", shoppingCartItems);
|
||||
|
||||
return "cart.html";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,13 +7,12 @@
|
||||
<link rel="stylesheet" type="text/css" href="/css/proList.css" />
|
||||
</head>
|
||||
<body>
|
||||
<!--/*@thymesVar id="cart" type="java.util.Set<.neu.neumall.entity.ShoppingCart>"*/-->
|
||||
<!--th:each="item:${cart}"-->
|
||||
<div class="cart mt">
|
||||
<!--/*@thymesVar id="productlist" type="java.util.Set<edu.neu.neumall.entity.ShoppingCart>"*/-->
|
||||
<div th:each="product:${productlist}" class="cart mt">
|
||||
<!-----------------site------------------->
|
||||
<div class="site">
|
||||
<p class=" wrapper clearfix">
|
||||
<span class="fl">购物车</span>
|
||||
<span class="fl">购物车</span>
|
||||
<img class="top" src="img/temp/cartTop01.png">
|
||||
<a href="index.html" class="fr">继续购物></a>
|
||||
</p>`
|
||||
@@ -37,7 +36,7 @@
|
||||
<dl class="clearfix">
|
||||
<dt class="fl"><img src="img/temp/cart01.jpg"></dt>
|
||||
<dd class="fl">
|
||||
<p th:text="${item}"></p>
|
||||
<p>花瓶</p>
|
||||
</dd>
|
||||
</dl>
|
||||
</a>
|
||||
|
||||
Reference in New Issue
Block a user