2016-03-21 126 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

不客气。 –

相关问题