I implemented it so that it can be PUT, but when I was looking at the Request Method in the developer console of chrome, it turned out to be POST
? Because it became. ..
Looking at From Data, it is put.
After specifying post
for the action of the form tag, you can see from the source that put is realized by using the hidden type.
・ What is hidden type?
https://developer.mozilla.org/ja/docs/Web/HTML/Element/Input/hidden
It is used when you want to send a value without displaying it on the form.
--Thymeleaf code
sample.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv='Content-type' content='text/html; charset=utf-8' />
<title>test</title>
</head>
<body>
<!--Pay attention here-->
<form th:action="@{/user}" th:method="put">
<input class="btn btn-default btn-xs" type="submit" value="update" />
</form>
<!--Pay attention here-->
</body>
</html>
--Source code displayed on the screen (after thymeleaf expansion)
sample.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-type' content='text/html; charset=utf-8' />
<title>test</title>
</head>
<body>
<!--Pay attention here-->
<form action="/user" method="post">
<input type="hidden" name="_method" value="put"/>
<input class="btn btn-default btn-xs" type="submit" value="update" />
</form>
<!--Pay attention here-->
</body>
</html>
The form tag only supports the get
and post
methods.
Therefore, it seems that the method is to specify method =" post "
on the form tag and specify value =" put "
in the hidden type.
As a result, Request Method is POST
, but it is sent by PUT
because it is sent by the method specified by _method
. When I looked it up, it seems that other frameworks such as Rails also realize put in this way.
Recommended Posts