首页 > 解决方案 > 使用单声道在 if 语句中

问题描述

fun createTask(taskDTO: TaskDTO): Mono<Task>{
    taskDTO.name ?: run {
        throw IllegalArgumentException("You need to insert a valid name to your task")
    }
    if ((this.countByName(taskDTO.name ).map { it > 0 })) throw java.lang.IllegalArgumentException("This name is already attached to another task")
    return taskRepository.save(Task(name = taskDTO.name, description = taskDTO.description))
}

我希望这段代码检查结果countByName(taskDTO)是否大于 0,但它在 Mono<> 内,那么如何在不使用的情况下检查.block()呢?

标签: springspring-bootkotlinreactive

解决方案


推荐阅读