spring - 使用单声道在 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()
呢?
解决方案
推荐阅读
- python - 如何制作一个可以处理单个输入或输入列表的函数
- android - 如何知道手机何时连接到 WiFi 网络
- powershell - 多个-ne过滤器powershell
- r - 如何抑制 #> 由拼凑而成的 plot_layout() 输出
- c++ - 如何从 C++ 处理 C 库中不同大小的类型
- sql - CASE 语句仍然返回多行
- python - 使所有用户都可以访问由 pip 安装的程序 (aws cli)
- angular - 如何将对象属性绑定到 page-router-outlet 的 name 属性?
- spring-boot - Spring WebFlux WebClient 挂起并且 Mono.timeout 没有捕捉到它
- javascript - 如何将块按到主窗口底部?