Reputation: 522
I'm a laravel programmer and I have to develop a project for college in spring. I am not able to delete data from the table. In laravel, to delete data from the table, you have to create a form and inside this form you can pass the delete method. I've done a lot of research but the examples don't show the html.
Controller:
// Delete
@DeleteMapping("/autor/deletar/{id}")
public void delete(@PathVariable("id") long id)
{
authorservice.delete(id);
}
AuthorServiceImplement
@Override
public void delete(Long id) {
repositorio.delete(repositorio.findById(id).get());
}
Html
<a th:href="@{/autor/deletar/{id}(id=${author.id})}">
Deletar
</a>
When I try to delete, I get an error "get method not supported". Do I have to change anything in html anyway or is there something wrong with my code?
Upvotes: 0
Views: 55
Reputation: 365
If you are testing it via a web browser, it's always using the HTTP Method GET. You need to use Postman or Insomnia for exemple to send HTTP requests.
As you are using @DeleteMapping("/autor/deletar/{id}")
it says that this function is called when doing an HTTP request to /autor/deletar/{id}
with the method DELETE
EDIT
If you just want to test it via your web browser, you can always replace @DeleteMapping("/autor/deletar/{id}")
by @GetMapping("/autor/deletar/{id}")
Upvotes: 3