慕哥9229398
这是一种将Java对象转换为Map的方法public static Map ConvertObjectToMap(Object obj) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { Class> pomclass = obj.getClass(); pomclass = obj.getClass(); Method[] methods = obj.getClass().getMethods(); Map map = new HashMap(); for (Method m : methods) { if (m.getName().startsWith(“get”) && !m.getName().startsWith(“getClass”)) { Object value = (Object) m.invoke(obj); map.put(m.getName().substring(3), (Object) value); } } return map;}这是怎么称呼的 Test test = new Test() Map map = ConvertObjectToMap(test);
版权声明:本文为weixin_33134753原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。