1 回答

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊
我會(huì)將通用代碼提取到一個(gè)單獨(dú)的方法中:
public Something getSomething() {
client
.post()
.uri("PATH")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON_UTF8)
.body(requestBody))
.retrieve()
.bodyToMono(BookResponse.class)
.doOnNext(this::validateResponseStatus)
}
然后,在您的方法中,您只需要執(zhí)行以下操作:
Something something = getSomething();
return something.map(bookResponse -> new BookObject(bookResponse.getName(), bookRequest).doOnError(throwable -> logError(throwable));
或者
Something something = getSomething();
return something.map(BookResponse::getBookName).doOnError(throwable -> logError(throwable));
添加回答
舉報(bào)