BeanMapUtil.java 文件源码

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

项目:zooadmin 作者:
public static Object convertMap2Bean(Class type, Map map)
        throws IntrospectionException, IllegalAccessException,
        InstantiationException, InvocationTargetException {
    BeanInfo beanInfo = Introspector.getBeanInfo(type);
    Object obj = type.newInstance();
    PropertyDescriptor[] propertyDescriptors = beanInfo
            .getPropertyDescriptors();
    for (PropertyDescriptor pro : propertyDescriptors) {
        String propertyName = pro.getName();
        if (pro.getPropertyType().getName().equals("java.lang.Class")) {
            continue;
        }
        if (map.containsKey(propertyName)) {
            Object value = map.get(propertyName);
            Method setter = pro.getWriteMethod();
            setter.invoke(obj, value);
        }
    }
    return obj;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号