我知道spring3有@RequestHeader
来获取控制器中的单个请求标头。我想知道是否有一种简单的方法来获取所有请求标头?我希望有这样的事情:
@RequestMapping(value="/some/url",RequestMethod.GET)
public void endpoint(RequestParams params, BindingResult result, @RequestHeader MultiValueMap<String,String> headers, HttpServletRequest request, ModelMap model) {
}
目前我正在做这样的事情:
MultiValueMap<String,String> headers = new HttpHeaders();
for (Enumeration names = request.getHeaderNames(); names.hasMoreElements();) {
String name = (String)names.nextElement();
for (Enumeration values = request.getHeaders(name); values.hasMoreElements();) {
String value = (String)values.nextElement();
headers.add(name,value);
}
}