java获取bean中的所有属性

来源:互联网 发布:外贸网络销售平台 编辑:程序博客网 时间:2024/05/29 13:13

import java.beans.Introspector;
import java.beans.PropertyDescriptor;

//获取java bean

PropertyDescriptor[] props = null;
         try {
             props = Introspector.getBeanInfo(Bean.getClass(), Object.class).getPropertyDescriptors();             
             if (props != null) {
                 for (int i = 0; i < props.length; i++) {
                    String aa = props[i].getName();//获取bean中的属性
   
                    Object object = props[i].getPropertyType();//获取属性的类型
                         
                    }
                 }
         } catch (Exception e) {
         
         }
0 0
原创粉丝点击