【问题标题】:how to display 2 spring models in the same html table row using thymeleaf?如何使用 thymeleaf 在同一个 html 表格行中显示 2 个弹簧模型?
【发布时间】:2021-11-08 16:50:33
【问题描述】:

我想在 html 表格中显示以下行:

"$num out of $totalCount"

例如 num=5totalCount=8 我想在表中看到5 out of 8

这是我的代码:

...
        <tr>
            <td th:text="${num} out of ${totalCount}" />
        </tr>
...

我在控制器中添加了numtotalCount 作为模型。

我收到以下错误:

Could not parse as expression: "${num} out of ${totalCount}" 

这样做的正确语法是什么?

【问题讨论】:

    标签: java html spring thymeleaf


    【解决方案1】:

    Thymeleaf 中有几个用于字符串连接的选项。有关概述,请参阅 String concatenation with Thymeleaf

    在这种情况下,您可以使用以下内容:

    <td th:text="|${num} out of ${totalCount}|" />
    

    【讨论】:

      猜你喜欢
      • 2016-09-12
      • 2017-12-27
      • 2011-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多