model.addatribute(spring,mvc)有问题

sqyvllje  于 2021-07-08  发布在  Java
关注(0)|答案(1)|浏览(305)

我在object中有object(obj cartime(qnatity,obj product))中的obj product(id,name price),我应该如何向jsp添加atributes?现在我有了这样的东西,tomcat给了我exection[org.apache.jasper.jasperexception:an exception occurred processing]

@PostMapping(path = "/showCart", produces = "text/html; charset=UTF-8")
    public String showCart(Model model) {
        List<CartItem> cartItems = cart.getCartItems();

        model.addAttribute("cartItems", cartItems);
        return "showCart";
    }

jsp地址:

<c:forEach items="${cartItems}" var="cartItem">
            <tr>
                <td>${cartItem.getProduct.id}</td>
                <td>${cartItem.getProduct.name}</td>
                <td>${cartItem.getProduct.price}</td>
                <td>${cartItem.quantity}</td>
                <button name="remove" type="submit" value="${cartItem.getProduct.id}">REMOVE</button>
            </tr>
        </c:forEach>

代码还没有完成,但我首先需要解决这个问题。如有任何提示,我将不胜感激。

gev0vcfq

gev0vcfq1#

使用字段名(例如。 cartItem.product.id )而不是getter name

相关问题