/**
* - bean 2 map
* @param objList
* @return
* @author:
* @date:
*/
@SuppressWarnings("rawtypes")
public static List<Map<String, Object>> transBean2Map(List objList) {
if (objList == null) {
return null;
}
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
for (Object obj : objList) {
Map<String, Object> map = new HashMap<String, Object>();
try {
BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
PropertyDescriptor[] propertyDescriptors = beanInfo
.getPropertyDescriptors();
for (PropertyDescriptor property : propertyDescriptors) {
String key = property.getName();
// 過濾class屬性
if (!key.equals("class")) {
// 得到property對應的getter方法
Method getter = property.getReadMethod();
Object value = getter.invoke(obj);
map.put(key, value);
}
}
result.add(map);
} catch (Exception e) {
logger.error("transBean2Map Error ", e);
}
}
return result;
}