LoginSignup
0
0

More than 5 years have passed since last update.

SpringのFlashAttributeはRedirectViewしか返せない

Last updated at Posted at 2013-06-12
@RequestMapping(value="addcustomer", method=RequestMethod.POST)
public String addCustomer(@ModelAttribute("customer") Customer customer,
        final RedirectAttributes redirectAttributes) {

    redirectAttributes.addFlashAttribute("customer", customer);
    redirectAttributes.addFlashAttribute("message","Added successfully.");

    return "redirect:showcustomer.html";    
}

"redirect:"からはじまるStringはRedirectViewに変換されるのでFlashAttributeが使える
たとえば返り値が@ResponseBodyだとFlashAttributeは使えない。

org.springframework.web.servlet.mvc.support.RedirectAttributes to specify the exact set of attributes to use in case of a redirect and also to add flash attributes (attributes stored temporarily on the server-side to make them available to the request after the redirect). RedirectAttributes is used instead of the implicit model if the method returns a "redirect:" prefixed view name or RedirectView.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0