
jquery 请求:
$.ajax({ url: '/api/topic/${topic.id}', type: 'put', cache: false, async: false, dataType: 'json', headers: { "token": "${_user.token}", }, data: { title: title, content: content, tags: tags, }, success: function (data) { if (data.code === 200) { window.location.href = "/topic/" + data.detail.id } else { alert(data.description); } } }) 后台 controller:
@PutMapping(value = "/api/topic/{id}") public Result edit(@PathVariable Integer id, String title, String content, String tags) { System.out.println(title); System.out.println(content); System.out.println(tags); return success(); } 打印出来的结果全是 null,id 是有的
chrome 审查元素看了下,jquery 把 put 和 delete 请求都封装成 form data 后才发送的请求,但就算是 form data 格式的参数在后台也可以接收到的吧!!
求 v2 大佬解惑,万分感谢
1 night98 2019 年 2 月 25 日 springmvc 对于 put 和 delete 请求不会接收参数。可以考虑使用 url param |
2 night98 2019 年 2 月 25 日 准确来说是不解析 body 内容 |