验证对象中属性是否为null
2013-02-25 14:11
162 查看
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;
}
方法如下:
/**
* 验证对象中属性是否为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;
}
相关文章推荐
- Android 判断一个对象属性是否有null的值
- 用LinQ扩展方法,泛型扩展方法,实现自定义验证字符是否空、对象是否为null,及泛型约束使用,Action的使用
- as3对象销毁是否需要全部属性置null?
- mybatis 引用对象属性映射错误 or could not be found for the javaType (xxx.model) : jdbcType (null) combination.
- 对象转换成json串时,将null属性去除;以及枚举类的使用
- android 检查对象属性是否有一个为空
- 无法创建 SSIS 运行时对象。请验证 DTS.dll 是否可用及是否已注册。此向导无法继续而将终止
- 判断JavaScript对象为null或者属性为空
- 关于constructor 属性查看对象是否为数组详情
- Java判断一个对象属性是否为空
- SCRIPT5007: 无法获取属性“ui”的值: 对象为 null 或未定义
- 页面包含js的不同位置报错 SCRIPT5007: 无法获取属性“x”的值: 对象为 null 或未定义
- CXF webService 对象属性值为null或空时生成xml缺少该字段节点 解决办法
- js如何判断一个对象{}是否为空对象,没有任何属性
- 如何判断一个对象是否含有属性
- JS中判断对象是否含有某个属性的方法
- 在datagrid中,IE浏览器报错:SCRIPT5007: 无法获取属性“rowspan”的值: 对象为 null 或未定义
- js如何判断一个对象{}是否为空对象,没有任何属性
- 判断JS对象是否拥有某属性