Spring boot 带变量的Thymeleaf onclick href
我有一个带有Thymeleaf项目的Spring Boot,我在编写按钮的onclick时遇到了麻烦。我希望生成的url是例如Spring boot 带变量的Thymeleaf onclick href,spring-boot,thymeleaf,Spring Boot,Thymeleaf,我有一个带有Thymeleaf项目的Spring Boot,我在编写按钮的onclick时遇到了麻烦。我希望生成的url是例如/owners/1/edit。我尝试了许多串联,最新的是: th:onclick="'window.location.href=\'/owners/{id}/edit(id=${owner.id})\''" …但它的计算不正确,只显示/owner/{id}/edit(id=${owner.id}) 有什么想法吗?使用 Sonar给我一个错误,说明锚定
/owners/1/edit
。我尝试了许多串联,最新的是:
th:onclick="'window.location.href=\'/owners/{id}/edit(id=${owner.id})\''"
…但它的计算不正确,只显示/owner/{id}/edit(id=${owner.id})
有什么想法吗?使用
Sonar给我一个错误,说明锚定标签的非法位置(内部按钮)。锚定链接可以工作,但我在其他地方使用按钮:(如果你想使用按钮,请简单地将按钮放在标签内。我已经编辑了我的答案,检查它是否对你有效。它有效!我不知道你可以这样做,sonar很高兴。非常感谢。你可以使用修改后的方法,而不需要按钮。请参阅示例。因此,在你的情况下,应该是这样的:<代码>单击我!。
<a th:href="@{/owners/{id}/edit(id=${owner.id})}">
<button type="button"> some button text </button>
</a>