[英]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 实现使用
Router
和Handler
并且通常返回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.