list转list<Map<String,Object>>

直接转换,把list集合替换就好



if
(CollectionUtils.isNotEmpty(list)) { list.forEach(item -> { Map<String, Object> map = null; try { map = (Map<String, Object>) PropertyUtils.describe(item); map.remove("class"); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } listMap.add(map); });

//下面是项目业务需要代码,时间转换用 SimpleDateFormat simpleDateFormat
= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String format = null; for (Map<String, Object> map : listMap) { for (Map.Entry<String, Object> stringObjectEntry : map.entrySet()) { if (stringObjectEntry.getValue() instanceof Long) { format = simpleDateFormat.format(stringObjectEntry.getValue()); map.put(stringObjectEntry.getKey(), format); } } } }

 

posted @ 2021-09-14 19:33  小小菜包子  阅读(1058)  评论(0)    收藏  举报