java 把請求數據轉換成map數據
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);//給Map賦值
}
}
return map;
}
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);//給Map賦值
}
}
return map;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.