首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >org.springframework.expression.spel.SpelEvaluationException: EL1007E:在null上找不到属性或字段“items”

org.springframework.expression.spel.SpelEvaluationException: EL1007E:在null上找不到属性或字段“items”
EN

Stack Overflow用户
提问于 2020-05-01 21:28:07
回答 3查看 273关注 0票数 0

如何解决这个错误?我将thymeleaf和spring一起使用,在解析下面的html片段时出现错误。

org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'items' cannot be found on null当我向购物车添加一些东西时,它起作用了。问题是当它是空的时候。

`

代码语言:javascript
复制
<tr th:each="item : ${session.shoppingCart.items}">
    <td th:text="${item.book.id}"></td>
        <td th:text="${item.book.title}"></td>
        <td><span th:text="${item.book.price}"></span>cash</td>
        <td>
            <form action="#" th:action="@{/cart/update}" method="post">
                <input type="hidden" th:value="${item.book.id}" name="id"/>
                <input type="number" min="1" th:value="${item.quantity}" name="qty"/>
                <button type="submit">UPDATE</button>
            </form>
        </td>
        <td><span th:text="${item.subTotal}"></span>cash</td>
        <td>
            <form action="#" th:action="@{/cart/remove}" method="post">
                <input type="hidden" th:value="${item.book.id}" name="id"/>
                <button type="submit">remove</button>
            </form>
        </td>
    </tr>

`

EN

Stack Overflow用户

发布于 2020-05-01 23:02:34

现在出现了这样的错误。

代码语言:javascript
复制
     org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "!session.shoppingCart.items"
org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'items' cannot be found on null

  <div th:if="${!session.shoppingCart.items}">
    <tr th:each="item : ${session.shoppingCart.items}">
        <td th:text="${item.book.id}"></td>
            <td th:text="${item.book.title}"></td>
            <td><span th:text="${item.book.price}"></span>cash</td>
            <td>
                <form action="#" th:action="@{/cart/update}" method="post">
                    <input type="hidden" th:value="${item.book.id}" name="id"/>
                    <input type="number" min="1" th:value="${item.quantity}" name="qty"/>
                    <button type="submit">UPDATE</button>
                </form>
            </td>
            <td><span th:text="${item.subTotal}"></span>cash</td>
            <td>
                <form action="#" th:action="@{/cart/remove}" method="post">
                    <input type="hidden" th:value="${item.book.id}" name="id"/>
                    <button type="submit">remove</button>
                </form>
            </td>
        </tr>
    </div>
票数 0
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61543407

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档