The need for put, delete commits is essential in the rest service, but many of the current viewers do not support it. Therefore, some additional processing is required before using rest.
The specific solutions are as follows:
1, add a filterfirst. This filter is the key to achieving this function. Open web. XMLand add the following code (to be placed first):
Copy Code
<Filter> <Filter-name>Httpmethodfilter</Filter-name> <Filter-class>Org.springframework.web.filter.HiddenHttpMethodFilter</Filter-class> </Filter> <filter-mapping> <Filter-name>Httpmethodfilter</Filter-name> <Url-pattern>/*</Url-pattern> </filter-mapping>
This is going to intercept a method with _method .
2, front-end request modification
Standard Rest Delete requests Ajax notation:
$.ajax ({ "delete", Url:url, data: {"contentId": id}, function (data) { if (data.status = = 0) { alert ("Success! "); Location.reload (); Else { alert ("The operation failed! "+ Data.reason);}} );
This is the ideal way to request. However , the Delete method is not supported by the browser, so it should be changed to the following:
$.ajax ({ "post", Url:url, data: {"_method": "Delete"}, function (data) { if (data.status = = 0) { alert ("Success! "); Location.reload (); Else { alert ("The operation failed! "+ Data.reason);}} );
pay attention to the marked Red section. Typeto bePost, because if theGetwords,Datawill be ignored in the parameters. parameter, add_method, TellSpringthis isDeleterequest. If this is the form, add a hiddeninput,nameis a_methodcan be. This allows you to use it across browsersRestinterface.
Spring using form form to implement put, delete commits