카테고리 없음

list -> list<hashmap> 형태로 받기

루돌프___ 2019. 11. 14. 02:24

https://okky.kr/article/370962

불러오는 중입니다...

//공통 소스

public static <T> List<Map<String, Object>> convertListToMap(Collection<T> target) {

List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();

for (T element : target) {

Map<String,Object> resultMap = new HashMap<String,Object>();

Field[] fieldList = element.getClass().getDeclaredFields();

if (fieldList != null && fieldList.length > 0) {

try {

for (int i = 0; i < fieldList.length; i++) {

String curInsName = fieldList[i].getName();

Field field = element.getClass().getDeclaredField(curInsName);

field.setAccessible(true);

Object targetValue = field.get(element);

resultMap.put(curInsName, targetValue);

}

resultList.add(resultMap);

 

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

return resultList;