/** * 验证对象是否为空 * * @param entryParam * @return */ public static boolean validateEntryParam(Object entryParam) { // 对象为空,直接返回false if (null == entryParam) { return false; } // 判断entryParam对象各个变量是否为空,(有一个不为空,返回true) for (Field f : entryParam.getClass().getDeclaredFields()) { try { // 变量设置为可获取 f.setAccessible(true); // 如果是字符串,如果不为空,返回true // getType是字段的类型 if (f.getType() == String.class) { if (StringUtils.isNotBlank((String) f.get(entryParam))) { return true; } } else if (f.getType() == Integer.class && f.get(entryParam) != null) {//Integer类型 return true; } } catch (Exception e) { e.printStackTrace(); // 异常验证下一个 continue; } } return false; }
实际应用中的案例,希望对你有所帮助。