在典型的Spring JSP应用程序中,我有一个控制器方法,如:
@RequestMapping(method = RequestMethod.POST)
public String save(@Valid Customer customer, BindingResult bindingResult, Model model, RedirectAttributes redirectAttributes) {
if (bindingResult.hasErrors()) {
model.addAttribute("customer", customer);
return "customer/create";
}
customerRepository.save(customer);
redirectAttributes.addAttribute("id", customer.getId());
redirectAttributes.addFlashAttribute("flash.message", "customer.created");
return "redirect:/customer/{id}";
}
请注意redirectAttributes设置flash.message
。
在JSP中我会使用:
<c:if test="${not empty requestScope['flash.message']}">
${requestScope['flash.message']}
</c:if>
我如何用Thymeleaf实现这个目标?
答案 0 :(得分:1)
这有效:
${#vars['flash.message']}