刚才做项目的时候看到一篇写的很不错的博客,解决我之前对于RedirectAttributes的困惑,也给大家推荐下~

原文地址https://zhuanlan.zhihu.com/p/21353217?refer=pengsong-java

RedirectAttributesSpring mvc 3.1版本之出来的一个功能,专门用于重定向之后还能带参数跳转的的工具类


有两种带参的方式:

第一种:

redirectAttributes.addAttributie("param",value); 这种方法相当于在重定向链接地址追加传递的参数,例如:

redirectAttributes.addAttributie("param1",value1);

redirectAttributes.addAttributie("param2",value2);

return:"redirect:/path/list" 

以上重定向的方法等同于 return:"redirect:/path/list?param1=value1&param2=value2 " ,注意这种方法直接将传递的参数暴露在链接地址上,非常的不安全,慎用


第二种:

redirectAttributes.addFlashAttributie("param",value);
这种方法是隐藏了参数,链接地址上不直接暴露,但是能且只能在重定向的 “页面” 获取param参数值。其原理就是放到session中,session在跳到页面后马上移除对象。

如果是重定向一个controller中是获取不到该param属性值的。
除非在controller中用(@RequestPrama(value = "param")String param)注解,采用传参的方式。

页面获值例如:

redirectAttributes.addFlashAttributie("param1",value1);

redirectAttributes.addFlashAttributie("param2",value2);

return:"redirect:/path/list.jsp" 

在以上参数均可在list.jsp页面使用EL表达式获取到参数值${param}

controller获得redirectAttributes重定向的值例如

redirectAttributes.addFlashAttributie("param1",value1);

redirectAttributes.addFlashAttributie("param2",value2);

return:"redirect:/path/list/"

@RequestMapping("list")
public List<Student> list(@RequestPrama(value = "param1")String param1,
@RequestPrama(value = "param2")String param2,...
){
//TODO
//your code }

通过在controller中的list方法体中可以获取到参数值。

[转]关于重定向RedirectAttributes的用法的更多相关文章

  1. 关于重定向RedirectAttributes的用法(转)

    原文地址:https://zhuanlan.zhihu.com/p/21353217?refer=pengsong-java RedirectAttributes 是Spring mvc 3.1版本之 ...

  2. 关于重定向RedirectAttributes的用法

    刚才做项目,遇到了redirectAttributes使用的问题,上网找了找,看到一篇写的很不错的博客,解决我对于RedirectAttributes的困惑,也给大家推荐下. 原文链接:href=&q ...

  3. Spring MVC RedirectAttributes的用法解决办法

    Spring MVC RedirectAttributes的用法很久没发过技术贴了,今天对于一个问题纠结了2小时,遂放弃研究用另一种方法解决,奈何心中一直存在纠结,发帖求解 我先解释下什么是Redir ...

  4. Spring中RedirectAttributes的用法

    RedirectAttributes 是Spring mvc 3.1版本之后出来的一个功能,专门用于重定向之后还能带参数跳转的的工具类.他有两种带参的方式: 第一种: redirectAttribut ...

  5. Spring 4 中重定向RedirectAttributes的使用

    RedirectAttributes 的使用 @RequestMapping(value = "/redirecttest", produces = "applicati ...

  6. Linux重定向用法详解

    大家好,我是良许. 相信大家平时都会有需要复制粘贴数据的时候,如果是打开文件进行复制粘贴,就不可避免的需要较多的鼠标与键盘的操作,就会比较繁琐.那么有没有可以省掉这些繁琐操作的复制粘贴的方法呢? 答案 ...

  7. linux shell脚本编程笔记(五): 重定向

    I/O重定向 简述: 默认情况下始终有3个"文件"处于打开状态, stdin (键盘), stdout (屏幕), and stderr (错误消息输出到屏幕上). 这3个文件和其 ...

  8. 红帽学习笔记[RHCSA] 第三课[输出重定向、Vi编辑器]

    第三课 关于Linux的输入输出 输入输出 0 stdin 标准输入 仅读取 1 stdout 标准输出 仅写入 2 stderr 标准错误 仅写入 3 filename 其他文件 读取和/或写入 输 ...

  9. SpringMVC现实

    夹 一个.前言 两.spring mvc 核心类和接口 三.spring mvc 核心流程图 四.spring mvc DispatcherServlet说明 五.spring mvc 父子上下文的说 ...

随机推荐

  1. cors的实现原理

    如何辨认一个请求的源domain? 如何发送和处理cors请求? 优势 和 弱点 cookie 和 伪装 1. http://www.staticapps.org/articles/cross-dom ...

  2. SharePoint 2013怎样创建Wiki库

    们使用Wiki页面来分享知识,增进团队合作.下面我将向大家展示SharePoint 2013 Wiki的使用方法.教程我都将以这张Wiki页面(即当前页)为示例. 编辑页面 如要编辑页面,单击顶部Ed ...

  3. java截取字符串函数

    substring public String substring(int beginIndex)返回一个新的字符串,它是此字符串的一个子字符串.该子字符串始于指定索引处的字符,一直到此字符串末尾. ...

  4. Map和JSON的互相转换

    JSON-Lib方式 /**   * 函数注释:parseJSON2Map()<br>   * 用途:该方法用于json数据转换为<Map<String, Object> ...

  5. C#基础第七天-作业-利用面向对象的思想去实现名片-动态添加

    1.利用面向对象的思想去实现: (增加,修改,删除,查询,查询全部)需求:根据人名去(删除/查询).指定列:姓名,年龄,性别,爱好,电话. 多条添加 , 动态添加 名片 本系列教程: C#基础总结之八 ...

  6. 是时候用PerconaDB替换MySQL了

    Percona数据库服务器是MySQL的增强版,替代MySQL并不复杂. 一.PerconaDB的特性 1)查询速度更快,数据的一致性更好 2)服务器运行及其稳定 3)可以延迟分片,或者避免分片 4) ...

  7. metaspolit 命令大全

    一.msfconsole相关命令 二.database 三.autopwn自动化攻击工具 四.metaspolit常见渗透命令大全

  8. MySQL 5.6学习笔记(函数)

    1. 数学函数 ABS(x)   返回x的绝对值BIN(x)     返回x的二进制(OCT返回八进制,HEX返回十六进制)CEIL(x)或CEILING(x)   返回大于x的最小整数值EXP(x) ...

  9. Datagrid分页、排序、删除代码

    <%@ Page language="c#" Codebehind="default.aspx.cs" AutoEventWireup="fal ...

  10. mysql获得60天前unix时间示例

    在mysql中获取多少天前的unix时间的方法.首先根据now()获得当前时间,使用adddate()方法获得60天前时间,使用unix_timestamp()方法转换时间类型 select UNIX ...