[英]WebFlux - how to check if Mono<ResponseEntity<Flux<MyItem>>> is empty to return 404
[英]Mono<ServerResponse> vs Mono<ResponseEntity<MyPojo>> as return type in Java Spring Webflux @RequestMapping
關於使用Mono<ServerResponse>
與Mono<ResponseEntity<MyPojo>>
作為返回類型的小問題。
我看到一些示例,有時Mono<ServerResponse>
用作 Spring Webflux 的功能路由中的返回類型。
但也看到有時Mono<ResponseEntity<MyPojo>>
在 Spring 功能路由中用作返回類型的示例。
此外,有許多示例在 @Controller、@RequestMapping(Get、Post 映射等)中使用Mono<ResponseEntity<MyPojo>>
作為返回類型。
但是也有一些返回Mono<ServerResponse>
的例子。
請問,退換貨有什么區別?
The short of it, as I understand it, is that org.springframework.http.ResponseEntity
is from the original Spring Mvc Framework package and org.springframework.web.reactive.function.server.ServerResponse
is from the spring Reactive package.
反應式 package 具有“兼容性”模式,可讓您使用向后兼容的@RestController
注釋,並且它們通常會像以前一樣返回ResponseEntity
。
沒有兼容性功能的反應式 package 實現使用Router
和Handler
並且通常返回ServerResponse
。 有關 spring 的教程,請參閱構建反應式 RESTful Web 服務。
另請參閱 Spring WebFlux 指南,第1.4 章。 用於兼容性反應方式和1.5的注釋控制器。 功能方式的功能端點。
如果您深入了解Annotated Controllers
代碼,您會發現它使用了Functional Endpoints
代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.