恢复Java Bean属性
/** * 时代Java - nowjava.com 提 供 **/ //package com.nowjava; import java.beans.BeanInfo; import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.lang.reflect.Method; import java.util.Map; public class Main { public static void restoreProp(Object bean, Map<String, Object> propMap) { try { BeanInfo beanInfo = Introspector.getBeanInfo(bean.getClass()); /* 来自 *时 代 J a v a 公 众 号*/ PropertyDescriptor[] propertyDescriptors = beanInfo .getPropertyDescriptors(); for (PropertyDescriptor descriptor : propertyDescriptors) { String fieldName = descriptor.getName(); if (propMap.containsKey(fieldName)) { Method writeMethod = descriptor.getWriteMethod(); writeMethod.invoke(bean,