Delete or apply methods in thimeleaf

I would like to call @RequestMapping(value = "", method = RequestMethod.DELETE)in the form of spring timeleafa.

Is it possible to call the delete method or place a request from the timemeaf?

please give your suggestion about this.

+4
source share
2 answers

You can use th:methodfor this:

<form th:object="${commandObject}" th:action="@{/urlToCall}" th:method="delete">

This will create a hidden input element that Spring MVC will select:

<input type="hidden" name="_method" value="delete">
+12
source

Thymeleaf is an HTML template engine. HTML does not support methods putor deleteHTTP for its attribute method. So no, you cannot. However, you have alternatives.

javascript . HTTP-.

HiddenHttpMethodFilter hidden _method=put <input>, . -

<input name="_method" type="hidden" value="PUT" />
+3

Source: https://habr.com/ru/post/1544847/


All Articles