Thymeleaf using path variables to th:href

user962206 picture user962206 · Nov 17, 2015 · Viewed 105.1k times · Source

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>

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

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

Answer

Mario Rojas picture Mario Rojas · Mar 12, 2018

The right way according to Thymeleaf documention for adding parameters is:

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