springMVC将post请求转为delete/put请求
需要在web.xml文件配置
<!--
将POST请求转化为DELETE或者是PUT
要用_method指定真正的请求参数
-->
<filter>
<filter-name>HiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<!--
将POST请求转化为DELETE或者是PUT
要用_method指定真正的请求参数
-->
<filter>
<filter-name>HiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping> <filter-name>HiddenHttpMethodFilter</filter-name> <url-pattern>/*</url-pattern>
</filter-mapping>
在页面上使用隐藏的from提交 <form id="deleteF" action="" method="post"> <input type="hidden" name="_method" value="DELETE"/>
</form>
或者ajax请求提交
var url = "<c:url value="/product/delete"/>"+"/"+pid+".do";
$.ajax({
type : ‘post‘,
data : {‘_method‘:‘delete‘},(注意:‘_method‘:‘delete‘)
dataType : ‘json‘,
url : url,
success : function(data){
window.location.href="http://localhost:8080/product/findAll.do";
},
error:function(){
window.location.href="http://localhost:8080/product/findAll.do";
}
});
后端使用注解配置
@RequestMapping(value = "/delete/{pid}",method = RequestMethod.DELETE)
public String delete(@PathVariable("pid") String id) throws Exception{}
相关推荐
stoneechogx 2020-06-04
Guanjs0 2020-11-09
wmsjlihuan 2020-09-15
shishengsoft 2020-09-15
poplpsure 2020-08-17
CyborgLin 2020-08-15
Richardxx 2020-07-26
sunnyhappy0 2020-07-26
knightwatch 2020-07-19
wcqwcq 2020-07-04
chichichi0 2020-06-16
YAruli 2020-06-13
JF0 2020-06-13
84423067 2020-06-12
心丨悦 2020-06-11
zkwgpp 2020-06-04
litterfrog 2020-05-30
today0 2020-05-26