I use this method to save or update an existing recipe in my DB, the incoming object might not have an id property if the recipe is new. After saving the command to the db I need to redirect the user to the page that displays the recipe, in order to do this I need to get the id property out of the Mono returned by the recipeService.saveRecipeCommand(). How can I get this value out without calling the .block() method?
@PostMapping("recipe")
public String saveOrUpdate(@ModelAttribute("recipe") RecipeCommand command) {
RecipeCommand savedCommand = recipeService.saveRecipeCommand(command).block();
return "redirect:/recipe/" + command.getId() + "/show";
}
The error I'm getting is:
java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-2