我试图将一个引导ID(字符串)添加到列表对象中。最初它在while循环中迭代,无论哪个引导ID为null ..我将该leadid添加到列表对象..完成迭代后,该列表对象只处理失败的最后一个导线。实际上它也应该有其他字符串。
这是我的代码。
while(iterLeadIds.hasNext()) {
String leadId = (String) iterLeadIds.next();
BankBridgeServiceRequest bankBridgeServiceRequest = new BankBridgeServiceRequest();
bankBridgeServiceRequest.setLeadId(leadId);
bankBridgeServiceRequest.setType(BankBridgeMethodType.webservice_Create_Lead);
LOG.info("Sending to web service Rev Lead ID = " + bankBridgeServiceRequest.getLeadId());
bankBridgeServiceResponse = bankBridgeService.run(bankBridgeServiceRequest);
String responseString = bankBridgeServiceResponse.getResponseString();
List<String> list = new ArrayList<String>();
if(responseString == null) {
bankBridgeUtilResponse.setStatus(false);
list.add(leadId);
bankBridgeUtilResponse.setFailedLeadIds(list);
LOG.info("webservice Rev got null response from Lead ID ::"+leadId);
&#34;列表&#34;对象应该有许多失败的潜在客户。
是否需要进行任何更改?
谢谢,
答案 0 :(得分:1)
你的问题是你在循环中创建了列表,所以列表只包含你添加的最后一个元素。
移动它:
List<String> list = new ArrayList<String>();
在循环之前:
List<String> list = new ArrayList<String>();
while(iterLeadIds.hasNext()) {
String leadId = (String) iterLeadIds.next();
BankBridgeServiceRequest bankBridgeServiceRequest = new BankBridgeServiceRequest();
bankBridgeServiceRequest.setLeadId(leadId);
bankBridgeServiceRequest.setType(BankBridgeMethodType.webservice_Create_Lead);
LOG.info("Sending to web service Rev Lead ID = " + bankBridgeServiceRequest.getLeadId());
bankBridgeServiceResponse = bankBridgeService.run(bankBridgeServiceRequest);
String responseString = bankBridgeServiceResponse.getResponseString();
if(responseString == null) {
bankBridgeUtilResponse.setStatus(false);
list.add(leadId);
bankBridgeUtilResponse.setFailedLeadIds(list);
LOG.info("webservice Rev got null response from Lead ID ::"+leadId);