Spring MVC RestFul 中的 DELETE 传输方式
来源:互联网 发布:电商平台数据库设计 编辑:程序博客网 时间:2024/06/02 06:43
在Spring RestFul 中 当浏览器不支持PUT和DELETE传输协议时,可以在表单中添加一个隐藏域,此隐藏于的name属性为:_method如:
<form action="update" method="post"> ... <input type="hidden" name="_method" value="PUT"/></form>
但是Spring中默认的方法过滤器(org.springframework.web.filter.HiddenHttpMethodFilter)是只对POST传输协议进行判断。
自定义实现对GET的支持
public class MyHiddenHttpMethodFilter extends HiddenHttpMethodFilter{private String methodParam = DEFAULT_METHOD_PARAM;public void setMethodParam(String methodParam){Assert.hasText(methodParam, "'methodParam' must not be empty");this.methodParam = methodParam;}@Overrideprotected void doFilterInternal(HttpServletRequest request,HttpServletResponse response, FilterChain filterChain)throws ServletException, IOException {String paramValue = request.getParameter(methodParam);String _method = request.getMethod();if (StringUtils.hasLength(paramValue)) {String method = paramValue.toUpperCase(Locale.ENGLISH);boolean b = ("POST".equals(_method) && "PUT".equalsIgnoreCase(method)) || ( "GET".equals(_method) && "DELETE".equalsIgnoreCase(method));if( b ){HttpServletRequest wrapper = new HttpMethodRequestWrapper(request, method);filterChain.doFilter(wrapper, response);}else{}}else {filterChain.doFilter(request, response);}}private static class HttpMethodRequestWrapper extends HttpServletRequestWrapper {private final String method;public HttpMethodRequestWrapper(HttpServletRequest request, String method) {super(request);this.method = method;}@Overridepublic String getMethod() {return this.method;}}}
此类的实现是当使用DELETE协议时请求使用GET然后加上参数_method=DELETE;当使用PUT协议时请求使用POST然后加上_method=PUT
- Spring MVC RestFul 中的 DELETE 传输方式
- spring mvc RESTful 方式 拦截器
- Spring MVC restful风格之put and delete
- Restful Spring MVC
- Spring MVC Restful
- Restful Spring MVC
- spring mvc Restful架构
- spring MVC 乱码、restful
- Spring MVC Restful风格
- spring mvc restful工程demo
- Spring MVC RESTFul Web Services
- spring mvc restful 传入List
- php接受restful api设计中的delete put的接收方式
- Spring MVC中的四种提交方式
- restful中的@DELETE注解的问题
- 梦想Spring-MVC,Restful,GWT,RestWebService
- Spring MVC 示例-注解; RESTful 风格
- spring mvc restful service string/json/xml
- Android WIFI 类分析
- Android 在一个程序中启动另一个程序
- java 与 c++ 、 C# 之间的区别与联系
- 第三章 系统运作机制
- Android UI学习 - Menu菜单
- Spring MVC RestFul 中的 DELETE 传输方式
- 线程池在socket通信中的应用
- Requires VIBRATE permission
- Using openCV for Mac OS in XCode
- Windows Mobile程序全屏与非全屏
- Android 获取系统或SDCARD剩余空间信息
- magent编译出错
- css解决td单元格内文字溢出
- Out-of-order execution