2 回答

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超5個(gè)贊
getDocumentIds是一個(gè)整數(shù)列表,我需要遍歷該列表并檢查該特定 id 是否有效。
您可以使用anyMatch來驗(yàn)證是否id存在任何文檔(假設(shè)返回值null)。
if(memberNoteResource.getDocumentIds()
.stream()
.anyMatch((id)-> repositoryService.findById(Document.class,id) == null)) {
throw new ApiException(ApiErrorCode.DEFAULT_400,
"Save unsuccessful document id is not part of member note");
}

TA貢獻(xiàn)1890條經(jīng)驗(yàn) 獲得超9個(gè)贊
我想你想要的是類似的東西
memberNoteResource.getDocumentIds().stream()
.map((id)-> {
repositoryService.findById(Document.class, id);
}).map(Optional::ofNullable);
然后你可以進(jìn)一步用 .filter() 鏈接它來做更多的檢查。
添加回答
舉報(bào)