ObjectUtil.java 文件源码

java
阅读 36 收藏 0 点赞 0 评论 0

项目:FCat 作者:
/**
 * 对象到map
 * @param obj
 * @return
 */
public static Map<String, Object> objectToMap(Object obj) { 
    Map<String, Object> map = new HashMap<String, Object>();
    if(obj == null) {
        return map;      
    }
    try{
     BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());    
     PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();    
     for (PropertyDescriptor property : propertyDescriptors) {    
         String key = property.getName();    
         if (key.compareToIgnoreCase("class") == 0) {   
             continue;  
         }  
         Method getter = property.getReadMethod();  
         Object value = getter!=null ? getter.invoke(obj) : null;  
         map.put(key, value);  
     }    
    }catch(Exception e) {
        logger.error(e.getMessage());
    }
    return map;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号