将前台传回的HttpServletRequest转换成HashMap

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

 

 public static Map<String, Object> handleParamToMap(
   HttpServletRequest request) {
  Map<String, Object> map = new HashMap<>();
  for (Entry<String, String[]> entry : request.getParameterMap()
    .entrySet()) {
   String[] arr = entry.getValue();
   String result = "";
   if (null != arr && arr.length > 0) {
    for (int i = 0; i < arr.length; i++) {
     result += arr[i];
     if (i < arr.length - 1) {
      result += ",";
     }
    }
    map.put(entry.getKey(), result);
   }
  }
  return map;
 }

posted on 2017-11-01 10:22  instr  阅读(565)  评论(0编辑  收藏  举报

导航