<!-- 4、使用Rest风格的URI,将页面普通的post请求转为指定的delete或者put请求 -->
详细使用请参考这篇博客:地址:http://blog.csdn.net/pplcheer/article/details/74999748
Rest 风格的 URL. 以 CRUD 为例: 新增: /order POST 修改: /order/1 PUT update?id=1 获取:/order/1 GET get?id=1 删除: /order/1 DELETE delete?id=1 如何发送 PUT 请求和 DELETE 请求呢 ?
1. 需要在web.xml文件中配置 HiddenHttpMethodFilter
HiddenHttpMethodFilter org.springframework.web.filter.HiddenHttpMethodFilter HiddenHttpMethodFilter /* HttpPutFormContentFilter org.springframework.web.filter.HttpPutFormContentFilter HttpPutFormContentFilter /*
补充说明: 如果在web.xml中配置HttpPutFormContentFilter,配置如下
httpPutFormcontentFilter org.springframework.web.filter.HttpPutFormContentFilter httpPutFormContentFilter /*
需要注意的是,该过滤器只能接受enctype值为application/x-www-form-urlencoded的表单,也就是说,在使用该过滤器时,form表单的代码必须如下:
2. 需要发送 POST 请求 3. 需要在发送 POST 请求时携带一个 name="_method" 的隐藏域, 值为 DELETE 或 PUT jsp文件如下:Test Rest Get 在 SpringMVC 的目标方法中如何得到 id 呢? 使用 @PathVariable 注解 */ @RequestMapping(value = "/testRest/{id}", method = RequestMethod.PUT) public String testRestPut(@PathVariable Integer id) { System.out.println("testRest Put: " + id); return SUCCESS; } @RequestMapping(value = "/testRest/{id}", method = RequestMethod.DELETE) public String testRestDelete(@PathVariable Integer id) { System.out.println("testRest Delete: " + id); return SUCCESS; } @RequestMapping(value = "/testRest", method = RequestMethod.POST) public String testRest() { System.out.println("testRest POST"); return SUCCESS; } @RequestMapping(value = "/testRest/{id}", method = RequestMethod.GET) public String testRest(@PathVariable Integer id) { System.out.println("testRest GET: " + id); return SUCCESS; } /** * @PathVariable 可以来映射 URL 中的占位符到目标方法的参数中. * @param id * @return */ @RequestMapping("/testPathVariable/{id}") public String testPathVariable(@PathVariable("id") Integer id) { System.out.println("testPathVariable: " + id); return SUCCESS; } @RequestMapping("/testAntPath/*/abc") public String testAntPath() { System.out.println("testAntPath"); return SUCCESS; }