Jeeva D :
나는 게시물에 대한 코드를 쓰고 있어요,하지만 난 검증에 몇 가지 문제에 직면하고있다.
getDocumentIds 정수의 목록입니다 무엇을 내가 필요하면 목록과 해당 ID가 유효한지 여부를 확인을 반복하는 것입니다.
i가 첫 번째 값을 취하고 그 값의리스트를 전달할 때, I는 다음 코드를 시도했지만있다. 그것은 첫 번째 후 값을 가지고 있지 않습니다.
Document document=
Optional.ofNullable(repositoryService.findById(Document.class,
memberNoteResource.getDocumentIds().stream()
.iterator().next())).orElse(null);
if (document == null) {
throw new ApiException(ApiErrorCode.DEFAULT_400,
"Save unsuccessful document id is not part of member note");
}
예상되는 결과는 내가 전달 된 모든 "getDocumentIds"를 확인해야하고 일부 ID가없는 경우 다음 내가 오류가 발생해야한다
또한 :
getDocumentIds
정수의 목록이며, 내가 필요한 것은 목록 및 해당 ID가 유효한지 여부를 확인을 통해 반복.
당신은 사용할 수 anyMatch
의 어떤 들어, 검증하기 위해 id
, (반환 값을 가정에는 문서가 존재하지 않습니다 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");
}