获取Java Bean简单属性写入方法
/*from n o w j a v a . c o m*/ //package com.nowjava; import java.beans.BeanInfo; import java.beans.IntrospectionException; import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main { public static Method getSimplePropertyWriteMethod(Object bean, String name) throws IllegalArgumentException,/*来 自 n o w j a v a . c o m - 时 代 Java*/ IllegalAccessException, InvocationTargetException { PropertyDescriptor propertyDescriptor = getPropertyDescriptor(bean, name); if (propertyDescriptor == null) throw new IllegalArgumentException("No property:" + name); return propertyDescriptor.getWriteMethod(); } public static PropertyDescriptor getPropertyDescriptor(Object bean, String name) { PropertyDescriptor[] descriptors = getPropertyDescriptors(bean); for (int i = 0; i < descriptors.length; i++) { if (name.equals(descriptors[i].getName())) return descriptors[i]; } return null; } public static PropertyDescriptor[] getPropertyDescriptors(Object bean) { BeanInfo beanInfo = null; try { beanInfo =