将一个mapList转换为beanList

public static <T> List<T> copyMapToBean(
   List<Map<String, Object>> resultMap, Class<T> cls) throws Exception {
  if (null == resultMap || resultMap.size() == 0 || null == cls) {
   return null;
  }
  // 结果集
  List<T> beanList = new ArrayList<T>();
  for (Map<String, Object> map : resultMap) {
   T bean = cls.newInstance();
   Set<String> keySet = map.keySet();
   for (String key : keySet) {
    BeanUtils.setProperty(bean, key, map.get(key));
   }

   beanList.add(bean);
  }

  return beanList;
 }

posted on 2017-11-01 10:44  instr  阅读(847)  评论(0编辑  收藏  举报

导航