【发布时间】:2021-11-03 22:04:34
【问题描述】:
请关于我在 Spring Webflux 中看到的一些返回类型的小问题。
在许多示例中,例如在线教程,Spring Webflux 项目的其余 Web 控制器将返回 MyPojo 的 Mono Mono<MyPojo> 类似
public Mono<MyPojo> monoPojo(String parameter) {
return WebClient.create("http://...").get().retrieve().bodyToMono(MyPojo.class)
.map(oneMyPojo -> unregisterRepository.insert(oneMyPojo))
;
}
但我也遇到了返回响应实体的项目,即 MyPojo Mono<ResponseEntity<MyPojo>> 的响应实体 Mono :
public Mono<ResponseEntity<MyPojo>> monoResponseEntityPojo(String parameter) {
return WebClient.create("http://...").get().retrieve().bodyToMono(MyPojo.class)
.map(oneMyPojo -> unregisterRepository.insert(oneMyPojo))
.map(ResponseEntity::ok)
;
}
我很难理解 Mono
谢谢
【问题讨论】:
-
ResponseEntity 允许您获取状态以及 ResponseEntity 为您提供的任何其他内容。实际上,您应该使用功能端点中的 ServerResponse,因为 ResponseEntity 来自 servlet mvc lib(如果我没记错的话)。 spring.getdocs.org/en-US/spring-framework-docs/docs/…
标签: java spring-webflux