问题描述
我有一个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()));
});
}
解决方法
您要做什么(从流到对象列表) 建议不要这样做,因为这样会失去将反应式(异步)转换为阻塞状态的能力。
,但是请确保您可以使用.block() 下面是一个
public List<String> getImageList() {
return someMethod()
.flatMapIterable(pojoAS -> pojoAS)
.map(pojoA -> "/images/"+pojoA.getImageName())
.collectList()
.block();
}