Springmvc中使用Rest风格

1.配置过滤器

<filter>
    <filter-name>hiddenfilter-name>
	<filter-class>org.springframework.web.filter.HiddenHttpMethodFilterfilter-class>
filter>
  <filter-mapping>
    <filter-name>hiddenfilter-name>
    <url-pattern>/*url-pattern>
  filter-mapping>

2.前端配置对应的请求

<form action="/restTest/1" method="post">
	<input type="hidden" name="_method" value="put">
    <input type="submit" value="提交">
form>

3.后端接受请求

这里在接受put请求时无法直接跳转到界面,因为跳转响应只支持get和post和head,这里可以让其重定向到一个请求,让其进行跳转!

@RequestMapping(value = "restTest/{id}",method = RequestMethod.PUT)
    public String restTest(@PathVariable Integer id){
        System.out.println("来到了rest测试:"+id);
        return "redirect:/local";
    }
@RequestMapping("local")
    public String local(){
        return "/result";
    }

你可能感兴趣的:(Springmvc)