我有以下简化的处理程序函数(Spring WebFlux 和使用 Kotlin 的功能 API)。但是,我需要提示如何检测空的 Flux,然后在 Flux 为空时将 noContent() 用于 404。
fun findByLastname(request: ServerRequest): Mono<ServerResponse> {
val lastnameOpt = request.queryParam("lastname")
val customerFlux = if (lastnameOpt.isPresent) {
service.findByLastname(lastnameOpt.get())
} else {
service.findAll()
}
// How can I detect an empty Flux and then invoke noContent() ?
return ok().body(customerFlux, Customer::class.java)
}