public Details getDetails(String id)throws InvokerException {詳細信息details = new Details();如何在迭代列表時返回所有值?
try {
URL url = new URL(BaseUrl, "/cxf/query/ask?id=" + id);
LOGGER.trace("URL: {}", url);
String xml = queryStore(url);
LOGGER.trace("Query result: {}", xml);
details = new Details();
InputSrc source = new InputSrc(new StringReader(xml));
ResultsContentHandler handler = new ResultsContentHandler();
XMLReader reader = XMLReaderFactory.createXMLReader();
reader.setContentHandler(handler);
reader.parse(source);
for (Hashtable<String,String> result : handler.getResultSet()) {
String baseId = result.get("baseId");
ArrayList<Details> list = getHistoryDetails(baseId);
for(Details t : list) {
details.setStatus(t.getStatus());
}
}
} catch (Exception e) {
throw new InvokerException(e);
}
return details;
}
我想要實現的是返回細節ArrayList中的所有項目。例如,我期望不止一種身份,但目前我只能獲得一種身份。
詳細類
public class Details {
private Core core;
private String department;
private GregorianCalendar timestampReceived;
private GregorianCalendar timestampReported;
private String status;
private GregorianCalendar timestampStatus;
private String explanation;
public Details(){}
public Details(Core core,
String department, GregorianCalendar timestampReceived,
GregorianCalendar timestampReported, String status,
GregorianCalendar timestampStatus, String explanation) {
super();
this.core = core;
this.department = department;
this.timestampReceived = timestampReceived;
this.timestampReported = timestampReported;
this.status = status;
this.timestampStatus = timestampStatus;
this.explanation = explanation;
}
public Core getCore() {
return core;
}
public String getDepartment() {
return department;
}
public GregorianCalendar getTimestampReceived() {
return timestampReceived;
}
public GregorianCalendar getTimestampReported() {
return timestampReported;
}
public String getStatus() {
return status;
}
public GregorianCalendar getTimestampStatus() {
return timestampStatus;
}
public String getExplanation() {
return explanation;
}
public void setCore(Core core) {
this.core = core;
}
public void setDepartment(String department) {
this.department = department;
}
public void setTimestampReceived(GregorianCalendar timestampReceived) {
this.timestampReceived = timestampReceived;
}
public void setTimestampReported(GregorianCalendar timestampReported) {
this.timestampReported = timestampReported;
}
public void setStatus(String status) {
this.status = status;
}
public void setTimestampStatus(GregorianCalendar timestampStatus) {
this.timestampStatus = timestampStatus;
}
public void setExplanation(String explanation) {
this.explanation = explanation;
}
}
然後你不是以你自己的方式填充你的ArrayList。改變你的期望或調查他們。我們不會爲你做。 –
很多人可能會說*返回'List'而不是*,*移動'Detail detail = new Details();'在循環*內,並*用這個新實例填充你的列表*但是看起來你沒有'你自己試過任何東西...... –
這是什麼'Details'類?它是如何工作的?向我們展示一些代碼! –