In general, HTTP requests only need to get and post to meet the project needs, and why also use restful may be to make the request URL look more intuitive, good-looking bar.
How to use RESTful requests: Get,post,put,patch,delete
SPRINGMVC is best for Get and post support by default, like Put,putch,delete, but it only supports the controller to receive URL pass parameters by default, and if we want to pass parameters like post, We need to do some settings in the backend and front end, such as the front-end request to manually set the content type of the request header to JSON, the backend also to match the parameters of the front-end setting controller to receive a request body, rather than the normal form or URL parameters, using requestbody annotations to receive, The SPRINGMVC will use the message processor to help convert the JSON-formatted request body to the Java bean, particularly troublesome, so there are three solutions available:
1. Modify Tomcat's Server.xml:
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" parseBodyMethods="POST,PUT,DELETE" URIEncoding="UTF-8" />
经过测试这种是可行的,只是ajax请求时需要设置请求头为
Content-Type: application/x-www-form-urlencoded
请求数据的内容格式是这样name=bbba&age=22
如果表单提交的话只需要设置请求编码application/x-www-form-urlencoded即可。
2、在web.xml中添加HttpPutFormContentFilter
参考 7444590
3、在web.xml中添加HiddenHttpMethodFilter
参考 7444321
I recommend using the 3rd solution, no reason, personal preference.
Configuring RESTful style controllers in Springmvc