需求:
List集合通过for循环更改对象里面的属性值。以下代码是通过for循环遍历对象,并将对象属性值更改后删除List中原Index位置对象重新将新对象add到Index位置即可实现对象更新。
...省略块...
public void setName(List<ScOperationBO> scOperationBOList) {
if (scOperationBOList == null) {
return;
}
for (int i = scOperationBOList.size() -1; i >= 0 ; i--) {
ScOperationBO scOperationBO = scOperationBOList.get(i);
SysDeptDTO sysDeptDTO = redisService.getCacheObject(scOperationBO.getId());
if (sysDeptDTO == null){
continue;
}
scOperationBO.setName(sysDeptDTO.getName());
scOperationBOList.remove(i);
scOperationBOList.add(i, scOperationBO);
}
}
...省略块...