标签:过滤器 orm -name public 分享图片 color put name spring
需要增加filter过滤器:HiddenHttpMethodFilter
可以将post请求转成delete和put方式的rest风格,当然也包括post;
<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>
@RequestMapping(value="/world/{id}",method={RequestMethod.PUT}) public String HelloworldPUT(@PathVariable(value="id") Integer id) { System.out.println("开始处理页面请求...PUT" + id); return "success"; } @RequestMapping(value="/world/{id}",method={RequestMethod.DELETE}) public String HelloworldDELETE(@PathVariable(value="id") Integer id) { System.out.println("开始处理页面请求...DELETE" + id); return "success"; } @RequestMapping(value="/world/{id}",method={RequestMethod.POST}) public String HelloworldPOST(@PathVariable(value="id") Integer id) { System.out.println("开始处理页面请求...POST" + id); return "success"; }
<form action="hello/world/15" method="post"> username:<input name="username" type="text" value="zhangpn"><br/><br/> password:<input name="password" type="password" value="18"><br/><br/> <input type="hidden" name="_method" value="DELETE"> <input type="submit" value="DELETE --->!"> </form> <br/> <br/> <form action="hello/world/48" method="post"> username:<input name="username" type="text" value="zhangpn"><br/><br/> password:<input name="password" type="password" value="18"><br/><br/> <input type="hidden" name="_method" value="PUT"> <input type="submit" value="PUT --->!"> </form> <br/> <br/> <form action="hello/world/88" method="post"> username:<input name="username" type="text" value="zhangpn"><br/><br/> password:<input name="password" type="password" value="18"><br/><br/> <input type="submit" value="PUT --->!"> </form>
@RequestMapping(value="/world/{id}",method={RequestMethod.XXX})
value值一样,method不同,URL处理不同!
标签:过滤器 orm -name public 分享图片 color put name spring
原文地址:https://www.cnblogs.com/batj/p/9206925.html