【发布时间】:2018-04-14 09:10:46
【问题描述】:
假设我在 Spring 中有一个带有 Kotlin 的控制器方法,我想返回 ResponseEntity<Test> 或 ResponseEntity<Error>。
如何在 Kotlin 中完成这项工作?我曾尝试输入ResponseEntitiy<Any> 或ResponseEntity<*>,但Kotlin 总是抱怨。
那么如何让返回类型真正通用呢?
@GetMapping
fun test(): Mono<ResponseEntity<?????>>
{
return Mono.just(1)
.map { ResponseEntity.ok(Test("OK") }
.switchIfEmpty(Mono.just(ResponseEntity.badRequest().body(Error("Error"))))
}
【问题讨论】:
标签: kotlin spring-webflux