I have this Thymeleaf template , where I want to add the guardianId in the href element, to generate a URL like http://localhost:8080/guardian/delete/8665 but I got this instead http://localhost:8080/guardian/delete/$%7Bguardian.id%7D
<tr th:each="guardian : ${guardians}">
<td class="col_id" th:text="${guardian.id}" ></td><!-- ID -->
<td class="col_name" th:text="${guardian.name}"></td><!-- NAME -->
<td class="col_name" th:text="${guardian.surName}"></td><!-- SURNAME -->
<td class="col_name" th:text="${guardian.description}"></td><!-- DESCRIPTION -->
<td class="col_name" th:text="${guardian.mobile}"></td><!-- MOBILE -->
<td class="col_name" th:text="${guardian.email}"></td><!-- EMAIL -->
<td class="col_name" >
<i class="fa fa-pencil-square-o" aria-hidden="true"></i>
</td><!-- EDIT -->
<td class="col_name" >
<a href="/guardian/delete/${guardian.id}" >
<i class="fa fa-times" aria-hidden="true"></i>
</a>
</td><!-- DELETE -->
</tr>
I also tried <a href="@{/guardian/delete/${guardian.id}}" >
with the same result :-(
I have this Thymeleaf template , where I want to add the guardianId in the href element, to generate a URL like http://localhost:8080/guardian/delete/8665 but I got this instead http://localhost:8080/guardian/delete/$%7Bguardian.id%7D
<tr th:each="guardian : ${guardians}">
<td class="col_id" th:text="${guardian.id}" ></td><!-- ID -->
<td class="col_name" th:text="${guardian.name}"></td><!-- NAME -->
<td class="col_name" th:text="${guardian.surName}"></td><!-- SURNAME -->
<td class="col_name" th:text="${guardian.description}"></td><!-- DESCRIPTION -->
<td class="col_name" th:text="${guardian.mobile}"></td><!-- MOBILE -->
<td class="col_name" th:text="${guardian.email}"></td><!-- EMAIL -->
<td class="col_name" >
<i class="fa fa-pencil-square-o" aria-hidden="true"></i>
</td><!-- EDIT -->
<td class="col_name" >
<a href="/guardian/delete/${guardian.id}" >
<i class="fa fa-times" aria-hidden="true"></i>
</a>
</td><!-- DELETE -->
</tr>
I also tried <a href="@{/guardian/delete/${guardian.id}}" >
with the same result :-(
4 Answers
Reset to default 2You probably want something like this:
<a th:href="@{~/guardian/delete/{id}(id=${guardian.id})}"></a>
But it really depends on your context, and what the url you want to generate. If your context already has /guardian in it, for example, you should use
<a th:href="@{/delete/{id}(id=${guardian.id})}"></a>
I don't know Thymeleaf, but I think you can find a solution on this page.
Thymeleaf - Link (URL) expressions
Try like this.
<a href="@{/guardian/delete/${guardian.id}}" >
I had same issues. I have googled it and found the solution.
You can use:
a th:href="@{/guardian/delete/{id}(id=${guardian.id})}
Even the below will work. Basically constant string is separated out from variable using single quotes
<a th:href="@{'/guardian/delete/'+${guardian.id}}>