2016-03-21 99 views
2

我有settings page和控制器是爲他Spring MVC的,Thymeleaf URL

@RequestMapping(value = "/settings/password/change", method = RequestMethod.GET) 
public String changePassword(Model model) { 
    return "account/changepassword"; 
} 

在此頁面上有header其中包含myaccount鏈接: <a class="link" th:href="${currentUser.nickname}"><li class="li">User profile</li></a> 但如果我打開頭settings page鏈接有網址:localhost:8080/settings/password/change/profilename 。而不是我需要的URL如:localhost:8080/profilename。我如何做到這一點?

回答

2

你得到/settings/password/change/profilename因爲th:href="${currentUser.nickname}"創建相對URL到當前路徑:<a href="profilename"/>

相反,嘗試爲了使用這個Thymeleaf syntax構建一個上下文相關的URL:

<a th:href="@{/{profilename}(profilename=${currentUser.nickname})}">link</a> 
+0

非常感謝你,它幫助到我! –

+0

不客氣。 –