public String getFieldData(List<?> list, String declaredMethod) {
List<String> result = list.stream().map(r -> {
try{
return r.getClass().getDeclaredMethod(declaredMethodName).invoke(r);
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
log.error("获取方法失败", e);
return null;
}
}).filter(Objects::nonNull).map(r -> (String) r).collect(Colletors.toList());
return String.join(",", list);
}
相关文章
- 12-12【java8】获取指定方法名的结果集