Java Map反射为一个POJO或Bean

	/**
	 * Java Map反射成POJO(ResourcesBean )
	 */
	private static ResourcesBean mapToObject(Map<String, Object> map,
			String ObjectBeanPath) {
		ResourcesBean resourcesBean = new ResourcesBean();
		try {
			Class clazz = Class.forName(ObjectBeanPath);
			for (Map.Entry<String, Object> entry : map.entrySet()) {
				Field filed = clazz.getDeclaredField(entry.getKey());
				filed.setAccessible(true);
				filed.set(resourcesBean, entry.getValue() != null ? String
						.valueOf(entry.getValue()) : "");
			}
		} catch (Exception e) {
			log.error(e);
		}
		return resourcesBean;
	}

 

你可能感兴趣的:(java MAP)