簡體   English   中英

Mono<serverresponse> 與 Mono <responseentity<mypojo> &gt; 作為返回類型 Java Spring Webflux @RequestMapping </responseentity<mypojo></serverresponse>

[英]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 實現使用RouterHandler並且通常返回ServerResponse 有關 spring 的教程,請參閱構建反應式 RESTful Web 服務

另請參閱 Spring WebFlux 指南,第1.4 章。 用於兼容性反應方式和1.5注釋控制器 功能方式的功能端點

如果您深入了解Annotated Controllers代碼,您會發現它使用了Functional Endpoints代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM