Thymeleaf 使用路径变量到 th:href [英] Thymeleaf using path variables to th:href

查看:64
本文介绍了Thymeleaf 使用路径变量到 th:href的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码,我正在迭代:

Here's my code, where I'm iterating through:

<tr th:each="category : ${categories}">
     <td th:text="${category.idCategory}"></td>
     <td th:text="${category.name}"></td>
     <td>
         <a th:href="@{'/category/edit/' + ${category.id}}">view</a>
     </td>
</tr>

它指向的 URL 应该是 /category/edit/<类别的 id>,但它说它无法解析表达式:

The URL it points to is supposed to be /category/edit/<id of the category>, but it says it could not parse the expression:

评估 SpringEL 表达式的异常:category.id"(类别列表:21)

Exception evaluating SpringEL expression: "category.id" (category-list:21)

推荐答案

根据用于添加参数的 Thymeleaf 文档 是:

<a th:href="@{/category/edit/{id}(id=${category.idCategory})}">view</a>

这篇关于Thymeleaf 使用路径变量到 th:href的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆