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

com.github.easilyuse.common.util.MapUtil Maven / Gradle / Ivy

The newest version!
package com.github.easilyuse.common.util;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 
 * 

* Title:MapUtil *

*

* Description: map相关工具类 *

* * @author linyb */ public class MapUtil { private static Logger logger = LoggerFactory.getLogger(MapUtil.class); /** * key首字母转大写 * * @param map * @return 返回key首字母大写,value不为空的map集合 */ public static Map getCapwordsKeyMap(Map map) { Map capWordsKeyMap = new HashMap<>(); if (!map.isEmpty()) { map.forEach((key, value) -> { String capwordsKey = StringUtil.capitalize(key); if (StringUtil.isNotBlank(value)) { capWordsKeyMap.put(capwordsKey, value); } }); } return capWordsKeyMap; } /** * 对象映射成key为首字母大写的map * * @param t * @return 返回key首字母大写,value不为空的map集合 */ public static Map getCapwordsKeyMap(T t) { Map params = new HashMap<>(); try { params = BeanUtils.describe(t); params.remove("class"); } catch (Exception e) { logger.error(e.getMessage(), e); } return getCapwordsKeyMap(params); } /** * 对象映射成map * * @param t * @return 返回value不为空的map集合 */ public static Map convertBean2Map(T t) { Map newParams = new HashMap<>(); try { Map params = BeanUtils.describe(t); params.remove("class"); params.forEach((key, value) -> { if (StringUtil.isNotBlank(value)) { newParams.put(key, value); } }); } catch (Exception e) { logger.error(e.getMessage(), e); } return newParams; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy