cn.smallbun.scaffold.framework.common.toolkit.MapUtils Maven / Gradle / Ivy
The newest version!
/*
* Copyright (c) 2018-2019.[zuoqinggang] www.pingfangushi.com
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package cn.smallbun.scaffold.framework.common.toolkit;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* MapUtils
*
* @author SanLi
* Created by [email protected] on 2018/1/11
*/
public class MapUtils {
public static Map getParameterMap(HttpServletRequest request) {
// 参数Map
Map properties = request.getParameterMap();
// 返回值Map
Map returnMap = new HashMap<>(16);
Iterator> entries = properties.entrySet().iterator();
Map.Entry entry;
String name;
String value = "";
while (entries.hasNext()) {
entry = entries.next();
name = entry.getKey();
Object valueObj = entry.getValue();
if (null == valueObj) {
value = "";
} else {
String[] values = (String[]) valueObj;
for (String value1 : values) {
value = value1 + ",";
}
value = value.substring(0, value.length() - 1);
}
returnMap.put(name, value);
}
return returnMap;
}
/**
* Bean 转Map
* @param o o
* @return {@link Map} result
*/
public static Map beanToMap(Object o) {
return JSONObject.parseObject(JSON.toJSONString(o), new TypeReference
© 2015 - 2025 Weber Informatics LLC | Privacy Policy