我有一个通过for-each循环进行迭代的列表。因此,我想要的是一旦将值设置为customerAttemptTemp.setIsActive("N") customerAttemptTemp.setAttemptCount();
的设置值应为1。
最终customerAttemptList列表的5次尝试计数必须为5。
这是代码段。
List<CustomerAttempt> customerAttemptList = customerAttemptService.findCustomerAttempts(customerAttemptWrong, _serviceContext);
for (CustomerAttempt customerAttemptTemp : customerAttemptList) {
customerAttemptTemp.setIsActive("N");
customerAttemptTemp.setIsActive( // **Where the count need to be updated**);
customerAttemptService.update(customerAttemptTemp, _serviceContext);
}
答案 0 :(得分:1)
您可以通过在循环外引入count
变量,然后在每次迭代后增加变量来实现此目的
int count = 1;
for(CustomerAttempt customerAttemptTemp : customerAttemptList) {
customerAttemptTemp.setIsActive("N");
customerAttemptTemp.setIsActive(count++);
customerAttemptService.update(customerAttemptTemp, _serviceContext);
}
答案 1 :(得分:0)
尝试一下。
for (int count = 0 ; count < customerAttemptList.size(); count++) {
customerAttemptList.get(count).setIsActive("N");
customerAttemptList.get(count).setIsActive(count + 1);
customerAttemptService.update(customerAttemptList.get(count), _serviceContext);
}