2014-02-07 39 views
3

我想學習Spring MVC & Thymeleaf。我有一個打印出一個鏈接&按鈕下面的HTML部分:Thymeleaf:網址中的參數不能被替換

<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?從我所看到的,我正在做文檔告訴我的事情。

回答

7

這應該工作:

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

我仍然無法使用圓括號工作的URL,但字符串連接工作在列表。 –

+0

@LeeTheobald不錯,我會刪除上面的一個。我沒有開發設置來測試它,但我認爲它可能從內存中工作。 – hutchonoid

1

答:

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

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