Timelare: parameters in URLs that are not replaced

I am trying to learn Spring MVC and Thymeleaf. I have the following part of HTML that displays a link and a button:

<ul th:each="item : ${typesMap}">
  <li>
    <a href="roomdetails.html" th:href="@{/roomdetails/${item.key}/${item.value}}">Linky</a>
    <button type="button" th:text="${item.value}">Button Text</button>
  </li>
</ul>

In two examples, the parameters in the link are never replaced. I always get something in the strings roomdetails/${item.key}/${item.value}in the HTML. The button works fine, although it will be displayed with the text found in $ {item.value} for each iteration of the loop.

Does anyone know why I cannot get the URLs in the format I want? From what I see, I do what the documentation tells me.

+3
source share
2 answers

This should work:

<a href="roomdetails.html"  th:href="@{'/roomdetails/' + ${item.key} + '/' + ${item.value}}"> 
+7
source

Answer:

<a href="roomdetails.html"  th:href="@{'/roomdetails/{paramsKey}/{paramsValue}'(paramsKey=${item.key}, paramsValue=${item.value})}"> 
Run codeHide result

I hope this can solve your problem.

+1

All Articles