How to return 404 with Spring WebFlux

前端 未结 3 1937
無奈伤痛
無奈伤痛 2021-02-15 23:47

I\'m having a controller like this one (in Kotlin):

@RestController
@RequestMapping(\"/\")
class CustomerController (private val service: CustomerService) {
             


        
3条回答
  •  一整个雨季
    2021-02-16 00:16

    Instead of throwing an exception the method's implementation can be changed to

    fun findById(@PathVariable id: String,
                 @RequestHeader(value = IF_NONE_MATCH) versionHeader: String?): Mono> =
        return service.findById(id)
            .map {
                // ETag stuff ...
                ok().eTag("...").body(...)
            }
            .defaultIfEmpty(notFound().build())
    

提交回复
热议问题