Java 是否可以根据某个过滤器将内容从一个通量插入另一个通量
我想根据某些条件将一个流量的内容填充到另一个流量中。以下是我的两项建议:Java 是否可以根据某个过滤器将内容从一个通量插入另一个通量,java,reactive-programming,spring-webflux,Java,Reactive Programming,Spring Webflux,我想根据某些条件将一个流量的内容填充到另一个流量中。以下是我的两项建议: Flux<templateVersionBo> templateVerion = templateVersionRepo.findAll(); Flux<templateBo> template = templateRepo.findAll(); 我不熟悉反应式编程。因此,即使不使用block/subscribe,也不确定是否可能 如果您的id是Long并且TemplateBo的版本为“withe
Flux<templateVersionBo> templateVerion = templateVersionRepo.findAll();
Flux<templateBo> template = templateRepo.findAll();
我不熟悉反应式编程。因此,即使不使用block/subscribe,也不确定是否可能 如果您的
id
是Long
并且TemplateBo
的版本为“wither”,您可以像以下那样映射模板:
// async collect id -> version map
Mono<Map<Long, TemplateVersionBo>> templateVersionsMapMono =
templateVerion.collectMap(TemplateVersionBo::getTemplateId);
// get version from map by template id
Flux<TemplateBo> templateBoFlux = templateVersionsMapMono
.flatMapMany(templateVersionsMap -> template
.map(templateBo -> templateBo.withTemplatePublishedVersion(
templateVersionsMap.get(templateBo.getId()).getVersion())));
//异步收集id->版本映射
Mono templateVersionsMapMono=
collectMap(TemplateVersionBo::getTemplateId);
//按模板id从映射中获取版本
Flux templateBoFlux=templateVersionsMapMono
.flatMapMany(TemplateVersionMap->template
.map(templateBo->templateBo.withTemplatePublishedVersion(
get(templateBo.getId()).getVersions());
最后,这种方法对我有效:
Mono<TemplateBo> templateBoMono = templateVersion
.collectMap(version -> version.getTemplateId())
.flatMap(publishedMap ->
template.map(templateBo -> {
templateBo.setPublished(publishedMap.get(templateId));
return templateBo;
}));
Mono templateBoMono=templateVersion
.collectMap(版本->版本.getTemplateId())
.flatMap(已发布地图->
template.map(templateBo->{
setPublished(publishedMap.get(templateId));
返回模板bo;
}));
Mono<TemplateBo> templateBoMono = templateVersion
.collectMap(version -> version.getTemplateId())
.flatMap(publishedMap ->
template.map(templateBo -> {
templateBo.setPublished(publishedMap.get(templateId));
return templateBo;
}));