Spring boot PUT、DELETE 请求无法定位方法及获取参数解决方案

来源:互联网 发布:linux系统启动流程简述 编辑:程序博客网 时间:2024/05/18 12:37

在使用spring boot过程中带着之前使用spring mvc的惯性思维操作,虽然spring boot已经整合了HiddenHttpMethodFilter , 结果却出现了 PUT方法不支持及无法获取到参数等问题;

 

解决方案:

 

1、将”_method”并到url,这样spring才能通过request.getParameter(this.methodParam);方法获取到_method = put才能将其转换为PUT请求定位至正确的控制器方法;


url:'/user?_method=PUT'


2、在参数前加注解@RequestBody , 通过json 传递数据:



  

$.post({    url:'/user?_method=PUT',    contentType:"application/json",    dataType:'json',    data:JSON.stringify(obj),    success:function (data) {        console.log(data);    }})

 
阅读全文
1 0
原创粉丝点击