首页 > 解决方案 > 如何使用 thymeleaf 在同一个 html 表格行中显示 2 个弹簧模型?

问题描述

我想在 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}" 

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

标签: javahtmlspringthymeleaf

解决方案


Thymeleaf 中有几个用于字符串连接的选项。有关概述,请参阅使用 Thymeleaf 进行字符串连接。

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

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

推荐阅读