我们有以下代码:
<div th:each="client : ${clients}">
<div th:each="purchase : ${client.purchases}">
<div th:each="product : ${purchase.products}">
<span th:text="${product.price}"></span>
<!-- <span id="2" th:text="${#aggregates.sum(products.{price})}"> </span> -->
<!-- <span id="2" th:text="${#aggregates.sum(products.![price])}"> </span> -->
</div>
</div>
</div>
输出结果为:
5.25
4.20
如果我取消注释第一条评论,我会收到错误
Exception evaluating SpringEL expression: "#aggregates.sum(products.{price})" (clients/clients:84)
如果我只取消注释第二条评论,我会收到错误:
Exception evaluating SpringEL expression: "#aggregates.sum(products.![price])" (clients/clients:85)
我尝试使用http://demo-dspace-cris.cineca.it/bitstream/123456789/26/1/usingthymeleaf.pdf
我正在使用thymeleaf 2.1.4
IT工作!
我应该使用:
<span id="2" th:text="${#aggregates.sum(purchase.products.![price])}"> </span>
答案 0 :(得分:4)
我在发布后自己想出来了!
<div th:each="client : ${clients}">
<div th:each="purchase : ${client.purchases}">
<span id="2"
th:text="${#aggregates.sum(purchase.products.![price])}"> </span>
<div th:each="product : ${purchase.products}">
<span th:text="${product.price}"></span>
</div>
</div>
</div>
输出:
9.45
5.25
4.20
帮助我很多的网站:http://forum.thymeleaf.org/aggregates-with-Spring-td3767446.html