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被繼承ide