0

My controller:

@GetMapping("/deletesocio/{id}")
public String delSocios(@PathVariable Long id){
    socioSer.borrar(socioService.buscarPorId(id));
    return "redirect:/webapp/socios";
}

My 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>

I want to delete the object by clicking this button who pass de id to the controller (well, thats the idea), could any one help me please?? thank you very much

1 Answers1

1

There are 2 parts to this...

1) The url expressions you should use is: @{/webapp/delsocio/{id}(id=${soc.idSocio})}

2) You can either make it a form with a submit button or style a regular link as a button as described here. Whichever solution you decide on will determine if you use th:action="@{/webapp/delsocio/{id}(id=${soc.idSocio})}" or th:href="@{/webapp/delsocio/{id}(id=${soc.idSocio})}".

Community
  • 1
  • 1
Metroids
  • 18,999
  • 4
  • 41
  • 52
  • Id like to use it without a form... should I have to put at that button a th:method? the url has to be with a th:href? What about the controller? It's getmaping? o maybe postmaping? I dont know why isn't still works – César Moscardó May 17 '17 at 18:11
  • If you want to do it without a form, then create a link and style it to look like a button (the post I linked to shows how to do that). In that case, the controller should be @GetMapping. – Metroids May 17 '17 at 18:43
  • Thank you, I didn't remembered I need a link for make the button works, this gave me 6 hours xD – César Moscardó May 17 '17 at 19:38