言语不多,直接上代码。
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; }
转化对象为map方法
时间: 2024-12-19 22:54:00