将Map转换为Java Bean
/** nowjava.com - 时 代 Java 提 供 **/ //package com.nowjava; import java.beans.BeanInfo; import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.lang.reflect.Method; import java.util.Map; public class Main { public static void transMap2Bean(Map<String, Object> map, Object obj) { try { BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass()); PropertyDescriptor[] propertyDescriptors = beanInfo .getPropertyDescriptors(); /** from * 时 代 J a v a 公 众 号 - nowjava.com **/ for (PropertyDescriptor property : propertyDescriptors) { String key = property.getName(); if (map.containsKey(key)) { Object value = map.get(key); // ??property???setter?? Method setter = property.getWriteMethod(); setter.inv