gst*_*low 21 java redirect spring spring-mvc
如果我用mycontroller方法写:
return "redirect:url";
Run Code Online (Sandbox Code Playgroud)
什么参数将传递给url(它可能是controler方法或jsp页面)?
Deb*_*kia 51
使用RedirectAttributes,您几乎可以将任何数据传递到重定向URL:
@RequestMapping(value="/someURL", method=GET)
public String yourMethod(RedirectAttributes redirectAttributes)
{
...
redirectAttributes.addAttribute("rd", "rdValue");
redirectAttributes.addFlashAttribute("fa", faValue);
return "redirect:/someOtherURL";
}
Run Code Online (Sandbox Code Playgroud)
当您使用addAttribute添加属性时,这将最终出现在目标重定向URL中.这些属性用于构造请求参数,客户端(浏览器)将redirect URL使用这些参数向其发送新请求.有了这个,您只能使用String或基元作为重定向属性.
当您使用时addFlashAttribute,这些属性会在重定向之前临时保存(通常在会话中),并且在重定向后可用于请求并立即删除.使用的优点flashAttributes是,您可以将任何对象添加为flash属性(因为它存储在会话中).
| 归档时间: |
|
| 查看次数: |
37092 次 |
| 最近记录: |