欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

springboot请求处理rest映射

程序员文章站 2022-07-15 16:10:01
...

前端的form标签只能提交get和post请求,如果想提交delete和put请求,则用以下方法

<form action="/user" method="post">
    <input name="_method" value="DELETE" type="hidden">
    <input type="submit" value="提交">
</form>
<form action="/user" method="post">
    <input name="_method" value="PUT" type="hidden">
    <input type="submit" value="提交">
</form>

需修改配置文件

spring:
  mvc:
    hiddenmethod:
      filter:
        enabled: true

controller方法(@RestController标注类):

 @RequestMapping(value = "/user",method = RequestMethod.DELETE)
    public String string(){
        return "delete请求";
    }
    @RequestMapping(value = "/user",method = RequestMethod.PUT)
    public String string2(){
        return "put请求";
    }

此时可以发起DELETE和PUT请求:

springboot请求处理rest映射

springboot请求处理rest映射

相关标签: springboot restful