如何在将 ID 传递给控制器的 Thymeleaf th:each 迭代中删除对象?
How to delete objects on a Thymeleaf th:each iteration passing an ID to the controller?
我的控制器:
@GetMapping("/deletesocio/{id}")
public String delSocios(@PathVariable Long id){
socioSer.borrar(socioService.buscarPorId(id));
return "redirect:/webapp/socios";
}
我的HTML
<tr th:each="soc : ${list}">
<td th:text="${soc.idSocio}">#</td>
<td th:text="${soc.nombreSocio}">Nombre</td>
<td class="button778"><button type="button"
th:href="@{/webapp/delsocio/${soc.idSocio}}"></button></td>
</tr>
我想通过点击这个将 de id 传递给控制器的按钮来删除对象(嗯,就是这个想法),有人可以帮我吗??非常感谢
这个有 2 个部分...
1) 您应该使用的 url 表达式是:@{/webapp/delsocio/{id}(id=${soc.idSocio})}
2) 您可以将其设为带有提交按钮的表单,或者将常规 link 样式设置为按钮 as described here。无论您决定使用哪种解决方案,都将决定您是使用 th:action="@{/webapp/delsocio/{id}(id=${soc.idSocio})}"
还是 th:href="@{/webapp/delsocio/{id}(id=${soc.idSocio})}"
.
我的控制器:
@GetMapping("/deletesocio/{id}")
public String delSocios(@PathVariable Long id){
socioSer.borrar(socioService.buscarPorId(id));
return "redirect:/webapp/socios";
}
我的HTML
<tr th:each="soc : ${list}">
<td th:text="${soc.idSocio}">#</td>
<td th:text="${soc.nombreSocio}">Nombre</td>
<td class="button778"><button type="button"
th:href="@{/webapp/delsocio/${soc.idSocio}}"></button></td>
</tr>
我想通过点击这个将 de id 传递给控制器的按钮来删除对象(嗯,就是这个想法),有人可以帮我吗??非常感谢
这个有 2 个部分...
1) 您应该使用的 url 表达式是:@{/webapp/delsocio/{id}(id=${soc.idSocio})}
2) 您可以将其设为带有提交按钮的表单,或者将常规 link 样式设置为按钮 as described here。无论您决定使用哪种解决方案,都将决定您是使用 th:action="@{/webapp/delsocio/{id}(id=${soc.idSocio})}"
还是 th:href="@{/webapp/delsocio/{id}(id=${soc.idSocio})}"
.