matrix.business.common.utils.RequestUtil Maven / Gradle / Ivy
package matrix.business.common.utils;
import lombok.extern.slf4j.Slf4j;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
/**
* 请求头工具
* @author wangcheng
*/
@Slf4j
public class RequestUtil {
/**
* 解析 request params 。
*
* @param request 请求头
* @return 请求头解析出来的参数
*/
public static Map parse(HttpServletRequest request) {
Map map = request.getParameterMap();
Map dataMap = new HashMap<>(map.size());
try {
String key;
String[] values;
String valueStr;
for (Map.Entry entry : map.entrySet()) {
key = entry.getKey();
values = entry.getValue();
if (values == null || values.length <= 0) {
dataMap.put(key, "");
} else {
valueStr = String.join(",", values);
dataMap.put(key, valueStr);
}
}
} catch (Exception e) {
log.error("parse request.getParameterMap() error", e);
throw new RuntimeException(e);
}
return dataMap;
}
}