我有收藏 X
我遍历它并像这样写:
<span th:each="a, stat : ${X}"
th:text="${X[__${stat.index}__].someProperty} + ','">
</span>
Run Code Online (Sandbox Code Playgroud)
我的另一个尝试是:
<span th:each="a, stat : ${X}" th:for="|a${stat.index}|"
th:text="${X[__${stat.index}__].someProperty} + ','">
</span>
Run Code Online (Sandbox Code Playgroud)
不幸的是输出是一样的.
跨度中的输出是:
test1, test2, test3,
Run Code Online (Sandbox Code Playgroud)
我希望输出为:
test1, test2, test3
Run Code Online (Sandbox Code Playgroud)
最后没有逗号.我怎样才能做到这一点?
解:
th:text与元素类型关联的属性值span 不得包含"<"字符.码:
<span th:each="a, stat : ${X}"
th:text=" ${X[__${stat.index}__].someProperty} + (${stat.size-1 > stat.index}? ',':'') ">
</span>
Run Code Online (Sandbox Code Playgroud) 我们有以下代码:
<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>
Run Code Online (Sandbox Code Playgroud)
输出是:
5.25
4.20
Run Code Online (Sandbox Code Playgroud)
如果我取消注释第一条评论,则会收到错误
Exception evaluating SpringEL expression: "#aggregates.sum(products.{price})" (clients/clients:84)
Run Code Online (Sandbox Code Playgroud)
如果我仅取消第二条评论的注释,则会收到错误:
Exception evaluating SpringEL expression: "#aggregates.sum(products.![price])" (clients/clients:85)
Run Code Online (Sandbox Code Playgroud)
我尝试使用http://demo-dspace-cris.cineca.it/bitstream/123456789/26/1/usingthymeleaf.pdf
我在用thymeleaf 2.1.4
有用 !
我应该使用:
<span id="2" th:text="${#aggregates.sum(purchase.products.![price])}"> </span>
Run Code Online (Sandbox Code Playgroud)