springMVC将post请求转为delete/put请求

发布时间:2020-03-21 08:01:15 作者:loserone
来源:网络 阅读:587

需要在web.xml文件配置
<!--
将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{}或者:
@DeleteMapping("/delete/{pid}")
br/>或者:
@DeleteMapping("/delete/{pid}")

推荐阅读:
  1. 如何降低报表应用的耦合度
  2. 如何应对报表开发中的复杂逻辑

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

springmvc将post请求转为de st te

上一篇:win7专业版64位,台式机睡眠和休眠后立即被唤醒

下一篇:Hyper-v环境下通过部署SCVMM进行物理机至虚拟机的转换

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》