Repository repo
Repository otherRepo
foreach entity : repo.FindAll() {
entityFind = otherRepo.FindById(entity.Prop)
if (entityFind != null) {
return entityFind
}
}
如何使用弹簧反应器来做到这一点?
我可以使用blockFirst()在otherRepo中进行搜索,但它会中断反应链
我也尝试过使用handle()来控制流程,但是找到项目时我不会中断流程
有什么想法吗?谢谢
您似乎只对第一张唱片感兴趣,只是给您一个想法,我们可以实现这样的目标。
return Flux.fromIterable(repo.findAll()) //assuming it returns a list
.map(entity -> otherRepo.findById(entity.property)) // for each entity we query the other repo
.filter(Objects::nonNull) // replace it with Optional::isPresent if it is optional
.next(); //converts the flux to mono with the first record