我想渲染一個由兩個單聲道或通量元素組成的物件(在代碼片段下方):
Mono<List<NodeDTO>> nodeDTOFlux = this.webClient
.get()
.uri(NODES_WITH_LIMIT limit)
.retrieve()
.onStatus(HttpStatus::isError,
response -> response.bodyToMono(String.class).flatMap(
msg -> Mono.error(new ApiCallException(msg, response.statusCode())))
)
.bodyToFlux(new ParameterizedTypeReference<Node>() {
}).map(node -> nodeMapper.toNodeDTO(node))
.collectList();
Mono<List<EdgeDTO>> edgeDTOFlux = this.webClient
.get()
.uri(EDGES_WITH_LIMIT limit)
.retrieve()
.onStatus(HttpStatus::isError,
response -> response.bodyToMono(String.class).flatMap(
msg -> Mono.error(new ApiCallException(msg, response.statusCode())))
)
.bodyToFlux(new ParameterizedTypeReference<Edge>() {
}).map(edge -> edgeMapper.toEdgeDTO(edge))
.collectList();
我嘗試使用 zip() 方法,但這不是我的目標我試圖回傳這樣的物件
GraphDataDTO graphDataDTO = new GraphDataDTO();
graphDataDTO.setEdgeDTOS(edgeDTOFlux);
graphDataDTO.setNodeDTOS(nodeDTOFlux);
我的控制臺中有結果,但物件回傳 { "nodeDTOS": { "scanAvailable": true }, "edgeDTOS": { "scanAvailable": true } } 回傳是在獲得所有通量之前完成的..有沒有解決方案無阻塞!提前致謝。
uj5u.com熱心網友回復:
這應該有效:
return Mono.zip(nodeDTOFlux, edgeDTOFlux)
.map(tuple2 -> GraphDataDTO.builder().nodeDTO(tuple2.getT1()).edgeDTO(tuple2.getT2()).build())
它創建了一個NodeDTOand元組EdgeDTO并將其映射到GraphDataDTO.
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/360880.html
標籤:春天 单核细胞增多症 反应式编程 弹簧-webflux 通量
