You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Thymeleaf时th:ref属性无法正常生成链接问题求助

问题原因

你使用了错误的Thymeleaf属性名,Thymeleaf不存在th:ref这个用于生成跳转链接的属性,你写的th:ref会被当作普通自定义属性处理,不会被解析为a标签的可跳转地址。

解决方法
  • 将代码中所有的th:ref替换为th:href即可。th:href是Thymeleaf专门用于动态生成a标签href属性的属性,会正确解析@{}格式的链接表达式。
    注意:Thymeleaf的动态渲染属性规则为th: + HTML原生属性名,a标签的跳转地址原生属性为href,因此对应的动态属性就是th:href

修正后的单链接代码:

<td><a th:href="@{/inativar/{id}(id=${cliente.id})}">Inativar</a></td>

修正后的完整列表循环代码:

<tr th:each="cliente : ${clientes}">
    <td th:text="${cliente.nome}"></td>
    <td th:text="${cliente.email}"></td>
    <td th:text="${cliente.tipo_utilizador}"></td>
    <td th:text="${cliente.data_criacao}"></td>
    <td><a th:href="@{/inativar/{id}(id=${cliente.id})}">Inativar</a></td>
</tr>
</tbody>

内容的提问来源于stack exchange,提问作者user3389425

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 08:45:02