标签:object row TE serial throw null return hashmap substr
java利用反射机制判断对象的属性是否为空:
Map<String,String> validateMap = new LinkedHashMap<String, String>();
validateMap.put("serial", "编号");
validateMap.put("major", "专业");
public static <T> String validateFiledIsNull(Map<String,String> fileds,T obj) throws Exception{
String ret ="";
for(String key:fileds.keySet()){
String getMethodStr = "get" + key.substring(0,1).toUpperCase()+key.substring(1);
Method m = obj.getClass().getMethod(getMethodStr);
Object value = m.invoke(obj);
if(value==null || value.toString().trim().equals("")){
if(!validateString(ret)){
ret=fileds.get(key);
}else{
ret+=","+fileds.get(key);
}
}
}
return ret;
}
标签:object row TE serial throw null return hashmap substr
原文地址:https://www.cnblogs.com/YuyuanNo1/p/9235276.html