java将list<Map>转为list<Object>对象
package com.sport.sporttrailwalkadminservermon.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
llect.Lists;
llect.Maps;
import com.sport.ailwalk.TrailActivityApplyExport;
import org.apachemons.beanutils.ConvertUtils;
import org.apachemons.beanutils.PropertyUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.util.StringUtils;
import flect.Type;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class ListUtil {
/**
* targetList 需要处理的list
* targetClass ⽬标class
* @return List 处理好的list
*/
public List listMapParseListObj(List targetList, Class targetClass){
/
/ 先获取该类的代理对象
Object obj = null;
try {
obj = wInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
// 将list转为list对象
for(int i = 0; i< targetList.size(); i++){
Map map = ((i);                  // 获取每个list⾥⾯每个map
Iterator it = map.keySet().iterator();
while(it.hasNext()){
String name = it.next().toString();      // 名称 key
String value = (name).toString(); // 值  value
try{
//取得值的类形
Class type = PropertyType(obj, name);
if(!StringUtils.isEmpty(type)){
PropertyUtils.setProperty(obj, name, vert(value, type));
}
}catch(Exception ex){
ex.printStackTrace();
}
}
}
// 将list<Map> 转为对象进⾏返回
List resListObj = wArrayList();
for (Object object : targetList) {
JSONObject jsonObject = JSON.JSONString(object));
resListObj.JavaObject((Type)targetClass));
}
/
/返回封装好的集合
return resListObj;
}
}
public static void main(String[] args) {
// 获取所有列表信息
List<Map> allListMap = wArrayList();
for (int i = 0; i < 5; i++) {
Map map = wHashMap();
map.put("name", "张三"+i);
map.put("birthday", "2015-05-06"+i);
allListMap.add(map);
}
object toListUtil listUtil = new ListUtil();
List<TextExport> textExportList = listUtil.listMapParseListObj(allListMap, TextExport.class);        System.out.String());
}
}
结果:

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。