Spring MVC重定向属性消息
成功或未成功执行某些类型的CRUD操作(CREATE,DELETE等)后,在显示消息时出现一些问题.我尝试使用重定向Flash属性,尽管我发现这些属性没有运气,并且根本无法显示消息.例如,我已经在Controller方法中声明了以下内容:
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
}
这是我的一个控制器中的函数的示例,在该控制器中,我声明将flash属性绑定到视图.我仍然在.jsp ${success}
中这样称呼flash属性,尽管我仍然无法显示它.我缺少什么使它无法正常工作吗?
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?
Model
接口的一种特殊化,controllers
可用于选择重定向方案的属性.由于添加redirect attributes
的意图非常明确-即用于redirect URL
.
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";
}