1.传入一个List对象,即该对象的属性名获取该List中所有该属性的值(属性类型为String)
private static List<String> getWybsListValueByName(String fieldName, List list) { try { List<String>lists=new ArrayList<>(list.size()); for (Object object:list) { String firstCode = fieldName.substring(0, 1).toUpperCase(); String getter = "get" + firstCode + fieldName.substring(1); Method method = object.getClass().getMethod(getter); Object value = method.invoke(object); lists.add(value.toString()); } return lists; } catch (Exception e) { return null; } }
来源:https://www.cnblogs.com/notably/p/12012715.html