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