java.lang.NullPointerException: element cannot be mapped to a null key 报错


 

 

这行代码 getSupplierLoginId 可为空时会报这种错误

Map<String, List<PurchaseOrderEntity>> collect = purchaseOrderEntities.stream().collect(Collectors.groupingBy(PurchaseOrderEntity::getSupplierLoginId));

代码修改后对空值进行过滤:

Map<String, List<PurchaseOrderEntity>> collect = purchaseOrderEntities.stream().filter(item-> StringUtil.isNotBlank(item.getSupplierLoginId())).collect(Collectors.groupingBy(PurchaseOrderEntity::getSupplierLoginId));

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM