通過Java8的語法可將實(shí)體list轉(zhuǎn)成 指定key的map岂傲,當(dāng)key出現(xiàn)重復(fù)值的時(shí)候會報(bào)“IllegalStateException: Duplicate key
” 的異常
解決方法:
//b覆蓋
allEmployees.stream()
.collect(Collectors.toMap(CompanyEntity::getEmployeeId,
Function.identity(), (a,b) -> b))
//保存a,不覆蓋
return this.fsRepo.getDosIdsWithDcs(dosIds).
stream().collect
(Collectors.toMap(YourModelDosClass::getDosId, v->v,
(v1,v2) -> v1));