首页 > 其他 > 详细

map转化bean

时间:2019-10-23 20:33:02      阅读:81      评论:0      收藏:0      [点我收藏+]
 1     public static <T> T mapToBean(Map<String, Object> map, Class<T> beanClass) {
 2 
 3         if (MapUtils.isEmpty(map)) {
 4             return null;
 5         }
 6 
 7         try {
 8             T t = beanClass.newInstance();
 9 
10             BeanInfo beanInfo = Introspector.getBeanInfo(t.getClass());
11             PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
12             for (PropertyDescriptor property : propertyDescriptors) {
13                 Method setter = property.getWriteMethod();
14                 if (setter != null) {
15                     setter.invoke(t, map.get(property.getName()));
16                 }
17             }
18             return t;
19         } catch (Exception ex) {
20             log.error("########map集合转javabean出错######,错误信息,{}", ex.getMessage());
21             throw new RuntimeException();
22         }
23     }

 

map转化bean

原文:https://www.cnblogs.com/jiangwg/p/11728397.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!