Spring MVC Redirect Attribute Messages

本秂侑毒 提交于 2020-03-25 07:51:12

问题


I am having some issues while displaying messages after I have successfully, or unsuccessfully performed some type of CRUD operation (CREATE, DELETE, etc). I have attempted to use Redirect Flash Attributes, although I have found no luck with these and I cannot get the message displaying at all. For example I have declared something like this within my Controller method:

public String DeleteAction(Model model, Object object, @RequestParam int id, RedirectAttributes attributes) {
   // Method logic
   object.delete(id);
   attributes.addFlashAttribute("success", "Object has been removed successfully.");
   return "index"; // View resolver redirect
}

That is an example of my function within one of my controllers where I declare the flash attribute to be binded to the view. I call the flash attribute like this within the .jsp ${success}, although I still cannot get it to display. Is there anything I am missing which is not enabling this to work?


回答1:


A specialization of the Model interface that controllers can use to select attributes for a redirect scenario. Since the intent of adding redirect attributes is very explicit -- i.e. to be used for a redirect URL.

@RequestMapping(value = "/delete", method = RequestMethod.GET)
public String DeleteAction(Model model, Object object, @RequestParam int id RedirectAttributes attributes) {
    object.delete(id);
    attributes.addFlashAttribute("success", "Object has been removed successfully.");
    return "redirect:" + "index";
}


来源:https://stackoverflow.com/questions/25710763/spring-mvc-redirect-attribute-messages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!