java利用反射机制判断对象的属性是否为空:
Map validateMap = new LinkedHashMap();
validateMap.put("serial", "编号");
validateMap.put("major", "专业");
public static String validateFiledIsNull(Map 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;
}