java - 是否可以根据某些过滤器将内容从一种助焊剂插入到另一种助焊剂
问题描述
我想根据某种条件将一个通量的内容填充到另一个通量中。这是我的两个助焊剂:
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;
我是反应式编程的新手。因此,即使不使用阻止/订阅,也不确定是否可能。
解决方案
如果您的版本id
是Long
并且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())));
推荐阅读
- c# - 使用文本、数字和 url 组合创建正则表达式
- r - 留下一个对数正态数据点并用列期望值+方差来近似它
- c# - 如何在gridview excel导出中添加下拉列表
- docker - docker run 立即退出?
- reactjs - 将默认坐标放在天蓝色反应地图代码中的位置(Map.js)
- javascript - Bootstrap 的选项卡更改功能在 ReactJS 中不起作用
- python-3.x - 根据python中的日期差异扩展数据框
- react-native - 如何使用 react-native-router-flux 在组件内实现选项卡
- css - 带有 alpha 通道的 hsl 用斜线分隔
- flutter - 定时器不取消颤振