WebFlux functional: How to detect an empty Flux and return 404?

前端 未结 4 1542
灰色年华
灰色年华 2020-12-30 10:03

I\'m having the following simplified handler function (Spring WebFlux and the functional API using Kotlin). However, I need a hint how to detect an empty Flux and then use n

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-30 10:42

    Use Flux.hasElements() : Mono function:

    return customerFlux.hasElements()
                       .flatMap {
                         if (it) ok().body(customerFlux)
                         else noContent().build()
                       }
    

提交回复
热议问题