判断字段是否有值,是否存在
public static boolean check(Object obj, String… param) {
boolean flag = true;
try {
if (obj == null) {
flag = false;
} else {
Method[] methods = obj.getClass().getMethods();
for (Method method : methods) {
if (method.getName().startsWith(“get”)) {
for (String p : param) {
if (method.getName().equalsIgnoreCase(“get” + p)) {
Object invoke = method.invoke(obj);
if (invoke == null || “”.equals(invoke)) {
flag = false;
}
}
}
}
}
}
} catch (BCException e) {
logger.error(“字段验证出现异常或者失败”, e);
return false;
} catch (Exception e) {
logger.error(“字段验证出现异常或者失败”, e);
return false;
}
return flag;
}
传一个对象,后面是要校验的字段,返回true表示存在,false表示不存在该字段或者值为null