小编yam*_*ami的帖子

Thymeleaf th:每个都在元素之间加入昏迷

我有收藏 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)

最后没有逗号.我怎样才能做到这一点?

解:

  1. 注意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)

java spring thymeleaf

9
推荐指数
1
解决办法
9473
查看次数

Thymeleaf 聚合不起作用

我们有以下代码:

<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)

aggregation spring-el thymeleaf

5
推荐指数
1
解决办法
4338
查看次数

标签 统计

thymeleaf ×2

aggregation ×1

java ×1

spring ×1

spring-el ×1