当我尝试在Thymeleaf中渲染视图时,出现错误Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'currentTemperature' cannot be found on object of type 'reactor.core.publisher.MonoMapFuseable' - maybe not public or not valid?Spring WebFlux文档指出“具有反应性类型包装器的模型属性已解析为其实际值”,但是将Mono 作为模型传递给视图会给我上述错误。 @RequestMapping(path = "/") @GetMapping public String home(Model model) { Mono<ThermostatState> thermostatState = thermostatClient.fetchThermostatState(); model.addAttribute("thermostatState", thermostatState); return "home"; }阻塞Mono 并解开内部值会使模板呈现不变,但是有点消除了使用反应式库的意义。 @RequestMapping(path = "/") @GetMapping public String home(Model model) { Mono<ThermostatState> thermostatState = thermostatClient.fetchThermostatState(); ThermostatState unwrappedState = thermostatState.block(); model.addAttribute("thermostatState", unwrappedState); return "home"; }该项目完全依赖于spring starter的依赖关系,并且没有显式的配置类。 (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 嗨,我也是Spring和Reactive编程的新手。但是我认为,可以通过这种方式来解决。 @RequestMapping(path = "/") @GetMapping public String home(Model model) { return thermostatClient.fetchThermostatState() .map(thermostatState -> { model.addAttribute("thermostatState", thermostatState); return "home"; }); } (adsbygoogle = window.adsbygoogle || []).push({}); 10-06 05:35