【发布时间】:2021-01-05 15:14:31
【问题描述】:
我使用此方法保存或更新数据库中的现有配方,如果配方是新的,传入对象可能没有 id 属性。将命令保存到数据库后,我需要将用户重定向到显示配方的页面,为此我需要从 recipeService.saveRecipeCommand() 返回的 Mono 中获取 id 属性。如何在不调用 .block() 方法的情况下获取此值?
@PostMapping("recipe")
public String saveOrUpdate(@ModelAttribute("recipe") RecipeCommand command) {
RecipeCommand savedCommand = recipeService.saveRecipeCommand(command).block();
return "redirect:/recipe/" + command.getId() + "/show";
}
我得到的错误是:
java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-2
【问题讨论】:
-
你能订阅那个对象吗?
标签: java spring reactive-programming spring-webflux reactive