private List<Objects> getObjects(Object object) {
List<Objects> objects = new ArrayList<>();
Field[] declaredFields = object.getClass().getDeclaredFields();
try {
for (int i = 1; i < declaredFields.length; i++) {
Field declaredField = object.getClass().getDeclaredField("code" + i);
declaredField.setAccessible(true);
String reviewerName = (String) declaredField.get(object);
Field declaredField2 = object.getClass().getDeclaredField("name" + i);
declaredField2.setAccessible(true);
String auditMsg = (String) declaredField2.get(object);
if (StringUtils.isNotEmpty(reviewerName)) {
objects.add(new Object(reviewerName,auditMsg));
}
}
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
return objects;
}
类里面有多个类似字段 且需批量操作
于 2024-06-19 16:08:26 首次发布