Springmvc中使用Rest风格

1.配置过滤器

<filter>
    <filter-name>hidden</filter-name>
	<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
  <filter-mapping>
    <filter-name>hidden</filter-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";
    }
发布了47 篇原创文章 · 获赞 6 · 访问量 2197

猜你喜欢

转载自blog.csdn.net/weixin_44467251/article/details/102705687