【问题标题】:Why Spring WebFlux ServerResponse doesn't have generic with a type of body为什么 Spring WebFlux ServerResponse 没有泛型类型的主体
【发布时间】:2019-04-04 11:41:04
【问题描述】:

我已经开始使用 Spring WebFlux,最近我想知道为什么 ServerResponse 没有泛型与正文类型。它与同步 ResponseEntity 不一致,并且会降低一般可读性。

fun getAggregatedData(@RequestBody request: Request): Mono<ServerResponse>

ServerResponse 中的响应主体类型从该方法的签名中是未知的。 是不是应该像下面这样?

fun getAggregatedData(@RequestBody request: Request): Mono<ServerResponse<Response>>

我想知道 ServerResponse 背后没有这种泛型类型的原因是什么?

【问题讨论】:

    标签: spring spring-webflux


    【解决方案1】:

    ServerResponseorg.springframework.web.reactive.function.server 包中,所以它应该在Spring WebFlux fn 中使用。

    如 Spring WebFlux 注解的参考文档中所述,you can still use ResponseEntity as a return value for Controllers

    【讨论】:

      【解决方案2】:

      也许您正在寻找 EntityResponse 它是 ServerResponse 的子类型并且具有通用类型

      https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/reactive/function/server/EntityResponse.html

      【讨论】:

        猜你喜欢
        • 2020-11-15
        • 2021-03-25
        • 1970-01-01
        • 2019-04-22
        • 2020-12-11
        • 1970-01-01
        • 2011-04-24
        • 2015-12-04
        • 1970-01-01
        相关资源
        最近更新 更多