Spring MVC重定向属性消息 [英] Spring MVC Redirect Attribute Messages

查看:69
本文介绍了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";
}

这篇关于Spring MVC重定向属性消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆