java bean 转 map

    /**
	 * - bean 2 map
	 * @param objList
	 * @return  
	 * @author: 
	 * @date: 
	 */
	@SuppressWarnings("rawtypes")
	public static List> transBean2Map(List objList) {
		if (objList == null) {
			return null;
		}
		List> result = new ArrayList>();
		for (Object obj : objList) {
			Map map = new HashMap();
			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;
	}

 

你可能感兴趣的:(Java并发编程分享,java,bean,转,map,java,bean转map,beantomap,java,bean)