Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 带变量的Thymeleaf onclick href_Spring Boot_Thymeleaf - Fatal编程技术网

Spring boot 带变量的Thymeleaf onclick href

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给我一个错误,说明锚定

我有一个带有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给我一个错误,说明锚定标签的非法位置(内部按钮)。锚定链接可以工作,但我在其他地方使用按钮:(如果你想使用按钮,请简单地将按钮放在标签内。我已经编辑了我的答案,检查它是否对你有效。它有效!我不知道你可以这样做,sonar很高兴。非常感谢。你可以使用修改后的方法,而不需要按钮。请参阅示例。因此,在你的情况下,应该是这样的:<代码>单击我!。
    <a th:href="@{/owners/{id}/edit(id=${owner.id})}"> 
         <button type="button"> some button text </button> 
    </a>