【问题标题】:Thymeleaf th:each access parameter in loopThymeleaf th:循环中的每个访问参数
【发布时间】:2020-08-10 22:11:08
【问题描述】:

我正在尝试在 html 表中添加一个数字,该数字将显示在电子邮件中。

到目前为止,我的代码如下:

<th:block th:each="param, rowStat: ${someList}">
    <th style="..." th:utext="#{some.translation(${param}, ${rowStat.count})}">superscript</th>
</th:block>

“someList”是一个简单的字符串列表,“some.translation”如下:

{0} (moreInfo)<sup>{1}</sup>

我想要达到的目标是:

String1 (更多信息)1
String2 (更多信息)2

我的问题是 thymeleaf 异常说在这种情况下禁止访问变量“param”。访问“rowStat.count”工作正常。

如果有更简单的方法来显示上标数字,我也可以。

【问题讨论】:

    标签: java html spring thymeleaf


    【解决方案1】:

    不允许使用param,因为这是 Thymeleaf 的保留字,用于检索请求参数。尝试将其更改为其他内容:

    <th:block th:each="myParam, rowStat: ${someList}">
        <th style="..." th:utext="#{some.translation(${myParam}, ${rowStat.count})}">superscript</th>
    </th:block>
    

    另请参阅此处的 Thymeleaf 文档:Request parameters

    param :用于检索请求参数。 ${param.foo}String[]foo 请求参数的值,所以 ${param.foo[0]} 通常用于获取第一个值。

    【讨论】:

    • 哦,我的主,这就是我所要做的。在不同的上下文中,它与“param”一起使用,但我想我在那里很幸运。谢谢!
    猜你喜欢
    • 2018-04-26
    • 2018-05-06
    • 1970-01-01
    • 2019-05-07
    • 1970-01-01
    • 2018-10-22
    • 1970-01-01
    • 2022-01-13
    • 2015-01-27
    相关资源
    最近更新 更多