https://stackoverflow.com/questions/56496426/project-reactor-mono-map-vs-mono-flatmap
Mono#flatMap takes a Function that transforms a value into another Mono. That Mono could represent some asynchronous processing, like an HTTP request.
On the other hand, Mono#map takes a Function that transforms a value of type T into another value, of type R. That transformation is thus done imperatively and synchronously (eg. transforming a String into an URL instance).
The other subtlety with flatMap is that the operator subscribes to the generated Mono, unlike what would happen if you passed the same Function to map.
本文深入探讨了Project Reactor中Mono.flatMap与Mono.map的使用场景与差异。Mono.flatMap接收一个将值转换为另一个Mono的函数,适用于异步处理如HTTP请求;而Mono.map接收一个将类型T的值转换为类型R的值的函数,转换过程同步进行,例如将字符串转换为URL实例。此外,flatMap会订阅生成的Mono,这是与map操作符的主要区别。
1672

被折叠的 条评论
为什么被折叠?



