您好,欢迎来到好土汽车网。
搜索
您的当前位置:首页JAVA实体类ListEntity转ListMap

JAVA实体类ListEntity转ListMap

来源:好土汽车网
JAVA实体类ListEntity转ListMap

public static List> EntityConvertMap(List list){ List> l = new LinkedList<>(); try {

for(T t : list){

Map map = new HashMap<>(); Method[] methods = t.getClass().getMethods(); for (Method method : methods) {

if (method.getName().startsWith(\"get\")) {

String name = method.getName().substring(3);

name = name.substring(0, 1).toLowerCase() + name.substring(1); Object value = method.invoke(t);

if(method.getGenericReturnType().toString().equals(\"class java.util.Date\")&&value!=null){ value = getNow((Date)value, \"yyyy-MM-dd HH:mm:ss\"); }

map.put(name,value); } }

l.add(map); }

} catch (Exception e) { e.printStackTrace(); }

return l;}

2.//list实体类转换成map

public static List> EntityConvertMap(List list){ List> l = new LinkedList<>(); try {

for(Dept t : list){

Map map = new HashMap<>(); Method[] methods = t.getClass().getMethods(); for (Method method : methods) {

if (method.getName().startsWith(\"get\")) {

String name = method.getName().substring(3);

name = name.substring(0, 1).toLowerCase() + name.substring(1); Object value = method.invoke(t); map.put(name,value); } }

l.add(map); }

} catch (Exception e) { e.printStackTrace(); }

return l;}

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- howto234.com 版权所有 湘ICP备2022005869号-3

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务