天天看點

java中擷取bean中所有的屬性

  public static void main(String[] args) {

    PropertyDescriptor[] props = null;

                try {

                        props = Introspector.getBeanInfo(new Gdzcn().getClass(), Object.class)

                                        .getPropertyDescriptors();

                } catch (IntrospectionException e) {

                }

                if (props != null) {

                        for (int i = 0; i < props.length; i++) {

                                try {

                                      String aa = props[i].getName();//擷取bean中的屬性

                                      Object object = props[i].getPropertyType();//擷取屬性的類型

                                        } catch (Exception e) {

                                }}}}