这个问题在这里已有答案:
有没有办法在Java Spring中获取所有请求参数?例如,在DJango中,您可以执行以下操作:
def view(request):
print request.META
从那里你可以看到发送的GET
或POST
参数,这有助于调试。到目前为止,我看到这样做的唯一方法是指定特定参数,例如@RequestParam(name="hello")
答案是肯定的!您可以通过简单的操作在端点中注入HttpServletRequest
对象来完成此操作:
@RequestMapping(value="/foo")
public String bar(HttpServletRequest request){
System.out.println("Here you can see the creation time: " + request.getSession().getCreationTime());
return "whatever string";
}
然后你可以按照以下方式列出你的参数:Get servlet parameters
改进它(来自@BoristheSpider的建议)你可以使用已经将所有参数映射到一个对象的MultiValueMap<String, String>
对象。所以你可以这样做:
@RequestMapping(value="/foo")
public String bar(@RequestParam MultiValueMap<String, String> parameters){ ... }
你可以在here中看到一个用法。