1.添加HttpServletRequest注解,也可以作为参数传递
@Autowired
protected HttpServletRequest request;
2.获取header
/**
* <h5>功能: 获取从request中传递过来的header信息</h5>
*
* @return Map<String, Object>
*/
public Map<String, Object> getHeaders() {
Map<String, Object> headerMap = new HashMap<String, Object>();
Enumeration<?> er = request.getHeaderNames();//获取请求头的所有name值
String headerName;
while(er.hasMoreElements()){
headerName = er.nextElement().toString();
headerMap.put(headerName, request.getHeader(headerName));
}
return headerMap;
}
可以和获取request中传递过来的参数信息组成一个完整的工具类,也可以作为一个完整BaseService被继承