验证对象中属性是否为null

来源:互联网 发布:2017西安程序员工资 编辑:程序博客网 时间:2024/06/10 16:57

import java.lang.reflect.Field;

方法如下:

/**
  * 验证对象中属性是否为null
  *
  * @param vo
  * @return
  * @throws ServiceException
  */
 protected boolean checkParamOfObj(AbstractVO vo) throws ServiceException,
   IllegalArgumentException, IllegalAccessException {
  log.info("服务层操作:验证对象中属性是否为null 方法checkParamOfObj(AbstractVO ["+ vo +"])");
  Field[] field1 = vo.getClass().getDeclaredFields();
  Boolean bool = false;
  for (int i = 0; i < field1.length; i++) {
   field1[i].setAccessible(true);
   if (field1[i].get(vo) != null) {
    bool = true;
   }
  }
  return bool;
 }