bodyToMono ParameterizedTypeReference 和 bodyToFlux 有什么区别

Ren*_*Abi 13 java webclient spring-boot

我没有看到这两种方法之间有任何主要的时间复杂度差异,它们都有工作魅力,我想了解这两种方法之间的主要区别是什么

我正在从服务中收集学生对象。

bodyToMono 参数化类型参考

public Mono<Collection<Student>> getStudents(String id) {

    return webClient
         .get()
         .uri(uriBuilder -> uriBuilder
             .path("/students/{0}")
             .build(id))
         .retrieve()
         .onStatus(HttpStatus::isError, resp -> resp.createException()
             .map(WebClientGraphqlException::new)
             .flatMap(Mono::error)
         ).bodyToMono(new ParameterizedTypeReference<Collection<Student>>() {}); // This Line
  }
Run Code Online (Sandbox Code Playgroud)

bodyToFlux 收集器

public Mono<Collection<Student>> getStudents(String id) {

    return webClient
         .get()
         .uri(uriBuilder -> uriBuilder
             .path("/students/{0}")
             .build(id))
         .retrieve()
         .onStatus(HttpStatus::isError, resp -> resp.createException()
             .map(WebClientGraphqlException::new)
             .flatMap(Mono::error)
         ).bodyToFlux(Student.class).collect(Collectors.toList()); // This Line
  }
Run Code Online (Sandbox Code Playgroud)

Col*_*lon 11

  • 如果您要检索单个项目,请使用 bodyToMono。它发出 0-1 个项目

  • 对于多个项目,请使用 bodyToFlux。它发出 0-N 个项目。

有关处理程序函数的更多信息spring 反应式 Web 处理程序