我有一个列表,该列表通过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);
}
最佳答案
您可以通过在循环外引入一个count
变量来做到这一点,然后在每次迭代后将其增加
int count = 1;
for(CustomerAttempt customerAttemptTemp : customerAttemptList) {
customerAttemptTemp.setIsActive("N");
customerAttemptTemp.setIsActive(count++);
customerAttemptService.update(customerAttemptTemp, _serviceContext);
}
关于java - 如何将迭代计数值设置为Java中的字段,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54760598/