简体   繁体   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

Small question regarding using Mono<ServerResponse> vs Mono<ResponseEntity<MyPojo>> as return type please.关于使用Mono<ServerResponse>Mono<ResponseEntity<MyPojo>>作为返回类型的小问题。

I am seeing examples where sometimes, Mono<ServerResponse> is used as return type in a functional route from Spring Webflux.我看到一些示例,有时Mono<ServerResponse>用作 Spring Webflux 的功能路由中的返回类型。

But also seeing examples where sometimes, Mono<ResponseEntity<MyPojo>> is used as return type in a Spring functional route.但也看到有时Mono<ResponseEntity<MyPojo>>在 Spring 功能路由中用作返回类型的示例。

Moreover, there are many examples where Mono<ResponseEntity<MyPojo>> is used in the @Controller, @RequestMapping (Get, Post mapping etc...) as return type.此外,有许多示例在 @Controller、@RequestMapping(Get、Post 映射等)中使用Mono<ResponseEntity<MyPojo>>作为返回类型。

But there are also few examples with returning Mono<ServerResponse> .但是也有一些返回Mono<ServerResponse>的例子。

May I ask, what is the difference between returning either one please?请问,退换货有什么区别?

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. 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.

The reactive package has a "compatibility" mode that lets you use the backward compatible @RestController annotations and they would generally return a ResponseEntity as before.反应式 package 具有“兼容性”模式,可让您使用向后兼容的@RestController注释,并且它们通常会像以前一样返回ResponseEntity

The Reactive package implementation without the compatibility features use a Router and Handler and generally return a ServerResponse .没有兼容性功能的反应式 package 实现使用RouterHandler并且通常返回ServerResponse See Building a Reactive RESTful Web Service for a tutorial from spring.有关 spring 的教程,请参阅构建反应式 RESTful Web 服务

See also the Spring WebFlux guide, chapters 1.4.另请参阅 Spring WebFlux 指南,第1.4 章。 Annotated Controllers for the compatibility reactive way and 1.5.用于兼容性反应方式和1.5注释控制器 Functional Endpoints for the functional way.功能方式的功能端点

If you look under the covers at the Annotated Controllers code you will see it uses the Functional Endpoints code.如果您深入了解Annotated Controllers代码,您会发现它使用了Functional Endpoints代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WebFlux - 如何检查 Mono <responseentity<flux<myitem> &gt;&gt; 为空返回 404 </responseentity<flux<myitem> - WebFlux - how to check if Mono<ResponseEntity<Flux<MyItem>>> is empty to return 404 Spring webflux控制器:消耗POJO vs Mono? - Spring webflux controller: consuming POJO vs Mono? 如何返回 Mono<ServerResponse> (作为副作用?) Mono.subscribe()? - How to return a Mono<ServerResponse> (as a side effect?) of Mono.subscribe()? 在 Spring Webflux 中组合多个 mono - Combine multiple mono in Spring Webflux Spring boot WebFlux:如何编写 Mono.map() 返回值? - Spring boot WebFlux : How to write Mono.map() return value? Spring Webflux 助焊剂<list<mypojo> &gt; 到通量<mypojo></mypojo></list<mypojo> - Spring Webflux Flux<List<MyPojo>> to Flux<MyPojo> 为什么要通过 Mono<ServerResponse> 来自 webflux 路由器中的处理程序函数而不是 Flux<ServerResponse> - Why pass Mono<ServerResponse> from handler function in webflux router and not Flux<ServerResponse> Java Spring Webflux - 插入一个空的 Mono 过滤器的结果? - Java Spring Webflux - inserting an empty Mono result of a filter? 如何在 Spring Webflux 中将 Mono 对象转换为其他 Mono 对象 - How to convert Mono object to other Mono object in Spring Webflux Spring WebFlux Mono 的异常中断 Mono.zip - Exception from a Spring WebFlux Mono interrupts Mono.zip
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM