1.BeanMap.create(pacdto)2.BeanUtils.copyProperties(x,x)3.BeanUtils.populate(x,x)--4、5有局限(String)4./** * @author: tianyong * @time: 2019/5/21 10:40 * @description:实体对象转成Map */public static MapString, Object object2Map(Obj
1.BeanMap.create(pacdto)2.BeanUtils.copyProperties(x,x)3.BeanUtils.populate(x,x)-->4、5有局限(String)4./** * @author: tianyong * @time: 2019/5/21 10:40 * @description:实体对象转成Map */public static Map<String, Object> object2Map(Object obj) { Map<String, Object> map = new HashMap<>(); if (obj == null) { return map; } Class clazz = obj.getClass(); Field[] fields = clazz.getDeclaredFields(); try { for (Field field : fields) { field.setAccessible(true); map.put(field.getName(), field.get(obj)); } } catch (Exception e) { e.printStackTrace(); } return map;}5./** * @author: tianyong * @time: 2019/5/21 10:40 * @description:Map转成实体对象 */public static Object map2Object(Map<String, Object> map, Class<?> clazz) { if (map == null) { return null; } Object obj = null; try { obj = clazz.newInstance(); Field[] fields = obj.getClass().getDeclaredFields(); for (Field field : fields) { int mod = field.getModifiers(); if (Modifier.isStatic(mod) || Modifier.isFinal(mod)) { continue; } field.setAccessible(true); field.set(obj, map.get(field.getName())); } } catch (Exception e) { e.printStackTrace(); } return obj;}