用反射判断多个属性值为空、或者直接抛出异常。
public static boolean allFieldIsNull(List<EmployeeCostMonth> employeeCostMonth1) {
int j = 1;
for (EmployeeCostMonth employeeCostMonth : employeeCostMonth1) {
try {
for (Field field : employeeCostMonth.getClass().getDeclaredFields()) {
field.setAccessible(true);
if (field.get(employeeCostMonth) == null) {
field.set(employeeCostMonth, "");
throw new TimeCardServiceException("000001","第"+j+"行报错!");
}
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
j++;
}
return true;
}