Bean2Map Map2Bean


###### BeanMap

import org.springframework.cglib.beans.BeanMap
Map example = BeanMap.create(bean);
 
  
###### Map转Bean
import org.apache.commons.beanutils.BeanUtils;
public static <T> T toBean(Class<T> clazz, Map map) {
    if(clazz == Map.class){
        return (T)map;
    }
    try {
        T bean = clazz.newInstance();
        BeanUtils.populate(bean, map);
        return bean;
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    }
    return null;
}

 
  

Map转Bean

你可能感兴趣的:(java)