转化对象为map方法

言语不多,直接上代码。

private  Map<String, Object> introspect(Object obj) throws Exception {
        Map<String, Object> result = new HashMap<String, Object>();
        BeanInfo info = Introspector.getBeanInfo(obj.getClass());
        for (PropertyDescriptor pd : info.getPropertyDescriptors()) {
            Method reader = pd.getReadMethod();
            if (reader != null)
                result.put(pd.getName(), reader.invoke(obj));
        }
        return result;
    }

 

posted on 2014-07-29 17:51  陈惟鲜的博客  阅读(163)  评论(0编辑  收藏  举报

导航