@RequestBody 是否应该在 Spring Webflux 中用 Mono Publisher 包装?

Is @RequestBody should be wrapped with Mono Publisher in Spring Webflux?

我正在研究 Spring-Webflux,我只是想知道我是否也应该用 Mono Publisher 包装我的 @RequestBody 对象?

例如: @RequestBody Mono<SavePriceViewModel> saveModel

示例:

@PostMapping("/item")
public Mono<ResponseEntity<PriceViewModel>> createHeaderAndItem(@RequestBody Mono<SavePriceViewModel> saveModel) {
   return service.createHeaderAndItem(saveModel).doOnSuccess(r -> log.debug("createHeaderAndItem() returned."));
}

请求主体不需要是单声道的,我们可以 return Mono<ResponseModel> 不需要 ResponseEntity

@PostMapping("/item")
public Mono<PriceViewModel> createHeaderAndItem(@RequestBody SavePriceViewModel saveModel) {
   return service.createHeaderAndItem(saveModel).doOnSuccess(r -> log.debug("createHeaderAndItem() returned."));
}

有关序列化和反序列化的更多信息,请查看此处。 https://docs.spring.io/spring/docs/5.1.9.RELEASE/spring-framework-reference/web-reactive.html#webflux-codecs

When decoding to a multi-value publisher (e.g. Flux), each TokenBuffer is passed to the ObjectMapper as soon as enough bytes are received for a fully formed object. The input content can be a JSON array, or line-delimited JSON if the content-type is "application/stream+json".