templist 根據傳入的pmid不同建立的list對應的model不同,但是又要獲得這個templist 的屬性像pointname,changethis等等,object不能用get+屬性名來獲取,只能用反射獲得字段陣列,進而獲取欄位名,字段值。
public string getexportprojmethodissueexcelpath(string currpid,string writestartdate,string writeenddate, listexportrecordslist) throws classnotfoundexception, illegalargumentexception, illegalacces***ception
if(f.getname().equals("thisvalue"))
if(f.getname().equals("changethis"))
if(f.getname().equals("changetotal"))
if(f.getname().equals("changerate"))
}rptdailydata exportdata=new rptdailydata();
exportdata.setwritedate(exportrecord.getwritedate());
exportdata.setpstatusreport(exportrecord.getpstatusreport());
exportdata.setpname(currproj.getpname());
exportdata.setmonitordate(exportrecord.getmonitordate());
exportdata.setweather(mimpl.showweatherinfobypidmdatetwo(currpid,exportrecord.getmonitordate().tostring().substring(0,9)));
exportdata.setwriteperson(exportrecord.getwriteperson());
exportdata.setmmname(exportrecord.getmmname());
exportdata.setissue(exportrecord.getissue());
exportdata.setpointname(pointname);
exportdata.setthisvalue(thisvalue);
exportdata.setchangethis(changethis);
exportdata.setchangetotal(changetotal);
exportdata.setchangerate(changerate);
//for(templist)
exportdatalist.add(exportdata);}}
exportor.sortbywritedate(exportdatalist);
// 呼叫匯出excel方法
result = exportor.exportrptdailyexcel(currproj,writestartdate,writeenddate, exportdatalist);
return result;
}注意:clazz 是類,f.get()要放入的是乙個object變數,即這個類的物件,在這裡就是按條件查出來的templist的每個物件例項
JAVA反射機制例項
test1.class public class test 3 getmethod 方法名,引數型別1,引數型別2.不常用 method cls.getmethod test2 int.class system.out.println method method 4 getmethods 獲取該類和...
java反射機制
private string getmethod catch instantiationexception e1 catch illegalacces ception e1 try catch illegalargumentexception e catch illegalacces ception...
Java反射機制
1.反射是指程式在執行時,可以通過反射機制拿到任何乙個類的內部所有資訊。2.可以獲得類的所有屬性資訊,包括私有屬性,並對其進行操作 3.可以獲得物件所對應的類 4.可以拿到本類,或父類中的方法,並且對其進行操作。常用方法 getname 獲得類對應的名稱 getdeclaredfields 獲得類中...