|  | 
 
 
        
          | 时 间 记 忆 |  
          | 
<<  < 2018 - 6 >  >>
| 日 | 一 | 二 | 三 | 四 | 五 | 六 |  
|  |  |  |  | 1 | 2 | 3 |  
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |  
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |  
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |  
| 25 | 26 | 27 | 28 | 29 | 30 |  |  |  
 
 
 
 
 
 
 
 
 |  | 
		
		|  |  
            | 
| 
|  |  
| 把Map的值赋给指定的对象 |  
| [ 2017-6-30 15:31:00 | By: 我家超超会发光 ] |  
| import java.lang.reflect.Field; import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 /**
 * 把Map的值赋给指定的对象
 *
 * @param map
 *            Map
 * @param obj
 *            对象
 * @return 赋值后的对象
 */
 public static Object mapToEntity(Map map, Object obj) {
 Field[] fields = obj.getClass().getDeclaredFields();
 Field.setAccessible(fields, true);
 for (int i = 0; i < fields.length; i++) {
 try {
 Field feild = fields[i];
 Class cls = feild.getType();
 String name = feild.getName();
 if ("MAPPER_NAME_SPACE".equals(name)) {
 continue;
 }
 Object value = getMapObjectValueByKey(map, name);
 if (cls.equals(Date.class)) {
 value = UncDate.parseDate(UtilAPI.turnString(value));
 }
 String setMethod = "set" + name.substring(0, 1).toUpperCase() + name.substring(1);
 Method method = obj.getClass().getMethod(setMethod, new Class[] { cls });
 method.invoke(obj, new Object[] { value });
 } catch (Exception ex) {
 ex.printStackTrace();
 }
 }
 return obj;
 }
 
 public static Object getMapObjectValueByKey(Map map, String key) {
 if (map.containsKey(key)) {
 return map.get(key);
 } else {
 return null;
 }
 }
 
 |  |  |  |  |