我通常检索如下 POST 参数:
@RequestMapping(method = RequestMethod.POST)
public ModelAndView create(
@RequestParam(value = "first_name", required = false) String firstName,
HttpServletRequest request
) {
但是如果 URL 中包含一些参数(例如 http://example.com/post/path?last_name=Smith
)怎么办?当 RequestMapping
为 POST 时,Spring 是否应该从 URL 和 POST 数据中获取所有参数?
基本上,Facebook 通过 POST 发送一个signed_request 参数,同时通过 URL 参数发送其他参数,例如 request_ids。我需要两者都得到。
最佳答案
But what if some parameters are in the URL like http://example.com/post/path?last_name=Smith? Is Spring supposed to grab all the parameters from both the URL and the POST data when RequestMapping is POST?
是的,spring将获取POST请求的所有参数值(形式和url)。但就你而言
@RequestParam(value = "first_name", required = false) String firstName,
将为空。因为在你的url中,参数名称是last_name
。 :D
关于spring - 当 POST 参数位于 URL 中时,Spring 3 中如何处理 POST 参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7470320/