知识的价值不在于占有,而在于使用。这篇文章主要讲述SpringMVC RequestMapping HiddenHttpMethodFilter相关的知识,希望能为你提供帮助。
SpringMVC隐藏方法:
使用PUT和DELETE方法。默认html支持GET和POST方法。通过HiddenHttpMethodFilter将POST转成PUT和DELETE方法。
1、将HiddenHttpMethodFilter配置到web.xml中
文章图片
< 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>
文章图片
2、控制器代码
文章图片
package com.tiekui.springmvc.handlers; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; @Controller public class HiddenHttpMethodFilterTest { @RequestMapping(value="https://www.songbingjia.com/android/testHiddenHttpMethod/{id}",method=RequestMethod.DELETE) public String testHiddenHttpMethodDelete(@PathVariable("id") Integer id){ System.out.println("Delete" + id); return "success"; }@RequestMapping(value="https://www.songbingjia.com/android/testHiddenHttpMethod/{id}",method=RequestMethod.PUT) public String testHiddenHttpMethodPut(@PathVariable("id") Integer id){ System.out.println("PUT" + id); return "success"; }}
文章图片
【SpringMVC RequestMapping HiddenHttpMethodFilter】3、视图代码
文章图片
< form action="testHiddenHttpMethod/1" method="post"> < input type="hidden"name="_method" value="https://www.songbingjia.com/android/PUT"> < input type="submit" value="https://www.songbingjia.com/android/testHiddenHttpMethodPUT"> < /form> < br> < form action="testHiddenHttpMethod/1" method="post"> < input type="hidden"name="_method" value="https://www.songbingjia.com/android/DELETE"> < input type="submit" value="https://www.songbingjia.com/android/testHiddenHttpMethodDelete"> < /form>
文章图片
推荐阅读
- SpringMVC RequestMapping 路径中ant风格的通配符
- SpringMVC RequestMapping RequestHeader注解
- oracle insertappendparallel随后查询的redo与磁盘读写
- SpringMVC RequestMapping 路径中带占位符的URL
- SpringMVC RequestMapping请求参数
- 运动健身小管家app下载|运动健身小管家app安卓版下载
- Fotor图片编辑器下载|Fotor图片编辑器app下载
- 掌上考勤app|掌上考勤最新版下载
- 在安卓6.0(及以上)设备上无法获取无线网卡MAC地址的解决方案