1 回答
![?](http://img1.sycdn.imooc.com/545869470001a00302200220-100-100.jpg)
TA贡献1827条经验 获得超8个赞
我会将通用代码提取到一个单独的方法中:
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)
}
然后,在您的方法中,您只需要执行以下操作:
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));
添加回答
举报