All Downloads are FREE. Search and download functionalities are using the official Maven repository.

matrix.business.common.utils.RequestUtil Maven / Gradle / Ivy

There is a newer version: 2.1.10
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy