反射獲取屬性名和屬性值

 Map map = new HashMap();
                BeanInfo beanInfo = Introspector.getBeanInfo(fcd.getClass());
                PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
                for(PropertyDescriptor pd :propertyDescriptors){
                    String name = pd.getName();
                    Object value = pd.getReadMethod().invoke(fcd);
                    if(value==null || StringUtils.isBlank(value.toString()) || name.equals("class")){
                        continue;
                    }
                    System.out.println(name+"-------------"+value);
                    map.put(name, value);
                }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章