什么是Thymeleaf中的requestScope等效使用flash消息?

时间:2014-05-07 21:10:41

标签: spring jsp spring-mvc thymeleaf

在典型的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实现这个目标?

1 个答案:

答案 0 :(得分:1)

这有效:

${#vars['flash.message']}