1 回答

TA貢獻1812條經(jīng)驗 獲得超5個贊
經(jīng)過大量試驗和錯誤并找到特定部分的解決方案后,我找到了適合我的解決方案。
public Flux<ItemDto> getAllItems() {
webClient.get()
.uri("/api/items?limit=1")//Used one to test
.exchange()
.expand(clientResponse -> {
List<String> links = clientResponse.headers().asHttpHeaders().getValuesAsList("LINK");
if(links.stream().anyMatch(link->link.contains("rel=\"next\""))){
for (String link : links){
if (link.contains("rel=\"next\"")){
return webClient.get()
.uri("/api/items?limit=1&" + link.substring(link.indexOf("after="), link.indexOf("&")))
.exchange();
}
}
}
return Flux.empty();
})
.flatMap(clientResponse ->
clientResponse.bodyToFlux(Map.class)
.map(ItemConverter::mapValueToItemDto));
}
不需要任何遞歸。只是更合適地使用擴展?,F(xiàn)在,其中的一部分(見下文)實際上可以分解成自己的方法,但由于它只有幾行,我選擇不這樣做。
webClient.get()
.uri("/api/items?limit=1" + after)//This after bit would be like what was passed as an argument before
.exchange();
添加回答
舉報