Spring boot 如何使用Thymeleaf在Spring Boot中设置Flash消息
我正试图在我的项目中实现Flash消息,该项目基于Spring Boot和Thymeleaf。但我发现到目前为止它还不是一个内置功能。如果是这种情况,重定向后向用户显示消息的选项是什么 我正在尝试实现中提出的解决方案,但它不适用于介绍中所述的Spring Boot。如前所述,将RedirectAttributes对象注入控制器,然后对该对象调用setFlashAttribute。e、 gSpring boot 如何使用Thymeleaf在Spring Boot中设置Flash消息,spring-boot,thymeleaf,flash-message,Spring Boot,Thymeleaf,Flash Message,我正试图在我的项目中实现Flash消息,该项目基于Spring Boot和Thymeleaf。但我发现到目前为止它还不是一个内置功能。如果是这种情况,重定向后向用户显示消息的选项是什么 我正在尝试实现中提出的解决方案,但它不适用于介绍中所述的Spring Boot。如前所述,将RedirectAttributes对象注入控制器,然后对该对象调用setFlashAttribute。e、 g @GetMapping("/test1") public String test1(RedirectAttr
@GetMapping("/test1")
public String test1(RedirectAttributes redirAttrs){
redirAttrs.addFlashAttribute("message", "This is message from flash");
return "redirect:/test2";
}
@GetMapping("/test2")
public String test2(Model model){
return "test2";
}
消息现在在“/test2”模型中可用,因此在test.html中显示消息,例如
<h2 th:text="${message}"></h2>
是,支持开箱即用。。。请看哪一个解释。