I would like to call the url via http delete method. I tried th:onclick and th:action but not working.
html code:
The th:method="delete" creates the hidden input field automatically for you. If you add it manually as well you will have it twice. Check the source code.
I still got the POST Error message after the recommendations here. I found out Spring ignores those hidden fields by default. The solution is to activate it in your application.properties file:
spring.mvc.hiddenmethod.filter.enabled=true
My working code in my application looks like this:
Form:
Controller:
@RequestMapping(value="/books/delete/{id}", method = RequestMethod.DELETE)
public String deleteBook(@PathVariable Long id) {
bookService.deleteBook(id);
return "books";
}