我有一个控制器操作,我认为应该是HTTP PUT请求,但当我在控制器操作中尝试使用@RequestParam时,Spring发出了警告。请求参数不允许用于HTTP PUT方法吗?这就是为什么Spring会拒绝它的原因吗?
@RequestMapping(value = "/{helpDocumentId}/vote", method = RequestMethod.PUT)
public void voteHelpfulness(@PathVariable long helpDocumentId, @RequestParam boolean isHelpful) {
helpManager.voteOnHelpDocument(helpDocumentId, isHelpful);
}
执行时,会抛出以下错误:
org.springframework.web.bind.MissingServletRequestParameterException: Required boolean parameter 'isHelpful' is not present
当然,isHelpful
参数是存在的。我可以让上面的代码在HTTP POST中完美运行,所以我知道这不是问题所在。
$.ajax({
url: "/help/" + helpDocumentId + "/vote.json",
type: "PUT",
data: {
isHelpful: isHelpful
},
success: function(response) {
// ....
}
});
PUT是正确的HTTP方法吗?这个操作修改了helpDocument
,但它并没有创建一个新的helpDocument
。
@RequestBody MultiValueMap<String, String>
。) - Arjan