【发布时间】:2013-05-30 21:02:01
【问题描述】:
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 detail = new Details();移入循环,然后填写您的列表有了这个新实例,但看起来你还没有自己尝试过任何东西...... -
这是什么
Details类?它是如何工作的?给我们看一些代码! -
@Code-Guru 与解决问题无关。
-
@LuiggiMendoza 当然是。如果 Details 类保留了多个项目的列表,则 OP 可能会错误地使用它。另一方面,如果 Details 只是一个项目,那么 OP 需要推出自己的解决方案(很可能使用某种 List)。