我们如何将Flux
> empFlux = getService((;//它将返回 Employe Employe { private String id; 私有字符串信息;}
需要将 empFlux 数据转换为 Mono<客户>客户>
公共类 CusData {
private String id;
private String dept;
private String info;
public String getId() {
return id;
}
}
公共类客户 {
private List<CusData> cusDataList;
public List<CusData> getCusDataList() {
return cusDataList;
}
public void setCusDataList(List<CusData> cusDataList) {
this.cusDataList = cusDataList;
}
} 公共类 雇用 {
private String id;
private String info;
}
如果我理解你的代码,你必须有这样的东西:
Mono<Customers> customers = getService().map( employee -> CusData.builder()
.id( employee.getId() )
.info( employee.getInfo() )
.build() )
.collectList()
.map( cusDatas -> Customers.builder()
.cusDataList( cusDatas )
.build() );
Flux 有一个方便的方法 collectList(( 来为你执行转换。 我在下面的示例中使用了字符串。
下面的代码片段。
Flux<String> stringFlux = Flux.just("Spring", "Spring Boot", "Reactive Spring")
.log();
Mono<List<String>> stringMono = stringFlux.collectList();