spring-webflux - 转换单声道> 列出
问题描述
我有一个Mono<List<PojoA>>
对象。我需要迭代PojoA and
一个新的表单列表List<String>
public List<String> getImageList() {
Mono<List<PojoA>> pojoAListMono = someMethod();
List<String> list = new ArrayList<String>();
pojoAListMono.flatMapMany(imageList -> {
imageList.stream().forEach(image -> list.add("/images/" + image.getImageName()));
});
}
解决方案
不建议您要求做什么(从流到对象列表),因为您失去了将反应式(异步)转换为阻塞状态的能力。
但确定你可以做到这一点 using.block() 下面是
public List<String> getImageList() {
return someMethod()
.flatMapIterable(pojoAS -> pojoAS)
.map(pojoA -> "/images/"+pojoA.getImageName())
.collectList()
.block();
}
推荐阅读
- angular - Angular StrictNullChecks:“对象可能是‘空’”
- reactjs - 无论如何在构建捆绑后启动reactjs?
- python - 有人能告诉我为什么我会收到这个错误吗?
- hadoop - 如果 HDFS 客户端上传文件失败会怎样?
- python - Python不断崩溃,出现分段错误
- ubuntu - 0.0.0.0/0 对于 nfs 配置是不可行的
- sql - 询问有关“选择...加入...”的 SQL
- python - 在保持参数常数/具有固定参数的同时,如何在 sympy 中象征性地进行偏导数?
- scala - Scala:方法值不符合类型界限
- javascript - 检查对象数组属性和嵌套对象属性的相等性