簡體   English   中英

Thymeleaf:URL中的參數未被替換

[英]Thymeleaf: Parameters In URLs Not Being Replaced

我正在努力學習Spring MVC和Thymeleaf。 我有以下HTML部分打印出一個鏈接和一個按鈕:

<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>

在這兩個示例中,鏈接中的參數永遠不會被替換。 我總是在HTML中以roomdetails/${item.key}/${item.value}的方式結束。 該按鈕工作正常,並將顯示在循環的每次迭代中在$ {item.value}中找到的文本。

有誰知道為什么我不能以我想要的格式獲取URL? 從我所看到的,我正在做文檔告訴我的內容。

這應該工作:

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

回答:

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

我希望這可以解決你的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM