狠狠做网站 百度一下免费查公司信息
狠狠做网站 百度一下,免费查公司信息,云商城在线下单,学编程哪个培训机构好Restful是一种软件架构风格、设计风格#xff0c;而不是标准#xff0c;只是提供了一组设计原则和约束条件。主要用于客户端和服务器交互类的软件#xff0c;基于这个风格设计的软件可以更简洁#xff0c;更有层次#xff0c;更易于实现缓存机制等。
Restful风格的请求是…Restful是一种软件架构风格、设计风格而不是标准只是提供了一组设计原则和约束条件。主要用于客户端和服务器交互类的软件基于这个风格设计的软件可以更简洁更有层次更易于实现缓存机制等。
Restful风格的请求是使用“url请求方式”表示一次请求目的的HTTP 协议里面四个表示操作方式的动词如下
GET 用于获取资源POST 用于新建资源PUT 用于更新资源DELETE 用于删除资源
例如
/user/1 GET得到 id 1 的 user/user/1 DELETE 删除 id 1 的 user/user/1 PUT更新 id 1 的 user/user POST新增 user
HiddenHttpMethodFilter
由于浏览器只支持发送get和post方式的请求SpringMVC 提供了 HiddenHttpMethodFilter 帮助将 POST 请求转换为 DELETE 或 PUT 请求
HiddenHttpMethodFilter 处理put和delete请求的条件
当前请求的请求方式必须为post当前请求必须传输请求参数_method
满足以上条件HiddenHttpMethodFilter 过滤器就会将当前请求的请求方式转换为请求参数_method的值因此请求参数_method的值才是最终的请求方式。
在web.xml中注册HiddenHttpMethodFilter
filterfilter-nameHiddenHttpMethodFilter/filter-namefilter-classorg.springframework.web.filter.HiddenHttpMethodFilter/filter-class
/filter
filter-mappingfilter-nameHiddenHttpMethodFilter/filter-nameurl-pattern/*/url-pattern
/filter-mapping目前为止SpringMVC中提供了两个过滤器CharacterEncodingFilter和HiddenHttpMethodFilter在web.xml中注册时必须先注册CharacterEncodingFilter再注册HiddenHttpMethodFilter原因 在 CharacterEncodingFilter 中通过 request.setCharacterEncoding(encoding) 方法设置字符集的request.setCharacterEncoding(encoding) 方法要求前面不能有任何获取请求参数的操作而 HiddenHttpMethodFilter 恰恰有一个获取请求方式的操作String paramValue request.getParameter(this.methodParam); // 查询所有员工数据
RequestMapping(value /employee, method RequestMethod.GET)
public String getEmployeeList(Model model){CollectionEmployee employeeList employeeDao.getAll();model.addAttribute(employeeList, employeeList);return employee_list;
}// 删除
RequestMapping(value /employee/{id}, method RequestMethod.DELETE)
public String deleteEmployee(PathVariable(id) Integer id){employeeDao.delete(id);return redirect:/employee;
}// 保存
RequestMapping(value /employee, method RequestMethod.POST)
public String addEmployee(Employee employee){employeeDao.save(employee);return redirect:/employee;
}// 更新
RequestMapping(value /employee, method RequestMethod.PUT)
public String updateEmployee(Employee employee){employeeDao.save(employee);return redirect:/employee;
}
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/92376.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!