首页 > 解决方案 > 是否可以根据某些过滤器将内容从一种助焊剂插入到另一种助焊剂

问题描述

我想根据某种条件将一个通量的内容填充到另一个通量中。这是我的两个助焊剂:

Flux<templateVersionBo> templateVerion = templateVersionRepo.findAll();
Flux<templateBo> template = templateRepo.findAll();

templateVersion 包含模板的 id。我想将模板版本填充到模板变量中,例如模板“publishedVersion”并返回 templateBo 通量,如下所示:

    if (templateVersion.getTemplateId().equals(template.getId()) {
            templateBo.setTemplatePublishedVersion(version);
    }
return templateBo;

我是反应式编程的新手。因此,即使不使用阻止/订阅,也不确定是否可能。

标签: javareactive-programmingspring-webflux

解决方案


如果您的版本idLong并且TemplateBo有“枯萎”,您可以映射您的模板,例如:

    // 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())));

推荐阅读