java 映射处理类方法和属性(get set)
set:
ResultPo resultPo=new ResultPo();
for(int j=6;j<st1.length;j++){//映射存储96时段
String setAttributeMethodName = "setH"+(j<10?"0"+j:j);
Method setAttributeMethod = null;
try {
setAttributeMethod = ResultPo.class.getDeclaredMethod(setAttributeMethodName);
try {
setAttributeMethod.invoke(resultPo,st1[j]);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
}
}
get:
TypePo obj=typeList.get(i);
for(int j=1;j<=96;j++){
String getAttributeMethodName = "getH"+(j<10?"0"+j:j);
Method getAttributeMethod = null;
try {
getAttributeMethod = TypePo.class.getDeclaredMethod(getAttributeMethodName);
try {
String corhr = (String) getAttributeMethod.invoke(obj);
content=content+"# "+typnum+" "+j+" "+corhr+" valley"+"\r\n";
typnum++;
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
}
}