国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

Spring RedirectAttributes參數跳轉代碼實例

瀏覽:2日期:2023-09-12 10:38:41

RedirectAttributes 是Spring mvc 3.1版本之后出來的一個功能,專門用于重定向之后還能帶參數跳轉的的工具類。他有兩種帶參的方式:

第一種:

redirectAttributes.addAttributie('prama',value); 這種方法相當于在重定向鏈接地址追加傳遞的參數,例如:

redirectAttributes.addAttributie('prama1',value1);redirectAttributes.addAttributie('prama2',value2); return:'redirect:/path/list' ;

以上重定向的方法等同于 return:'redirect:/path/list?prama1=value1&prama2=value2 ' ,注意這種方法直接將傳遞的參數暴露在鏈接地址上,非常的不安全,慎用。

第二種:

redirectAttributes.addFlashAttributie('prama',value); 這種方法是隱藏了參數,鏈接地址上不直接暴露,但是能且只能在重定向的 “頁面” 獲取prama參數值。其原理就是放到session中,session在跳到頁面后馬上移除對象。如果是重定向一個controller中是獲取不到該prama屬性值的。除非在controller中用(@RequestPrama(value = 'prama')String prama)注解,采用傳參的方式。頁面獲值例如:

redirectAttributes.addFlashAttributie('prama1',value1); redirectAttributes.addFlashAttributie('prama2',value2); return:'redirect:/path/list.jsp';

在以上參數均可在list.jsp頁面使用EL表達式獲取到參數值${prama*}

controller獲得redirectAttributes重定向的值例如:

redirectAttributes.addFlashAttributie('prama1',value1);redirectAttributes.addFlashAttributie('prama2',value2);return:'redirect:/path/list/'@RequestMapping('list')public List<Student> list(@RequestPrama(value = 'prama1')String prama1, @RequestPrama(value = 'prama2')String prama2,...){ //TODO //your code}

通過在controller中的list方法體中可以獲取到參數值。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Spring
相關文章:
主站蜘蛛池模板: 临颍县| 安乡县| 兴隆县| 仪陇县| 南昌市| 南皮县| 云和县| 泰顺县| 金川县| 永济市| 博客| 始兴县| 从江县| 繁峙县| 蛟河市| 玉龙| 湖州市| 永年县| 乌兰浩特市| 泸溪县| 都昌县| 香港| 房山区| 陕西省| 定安县| 大连市| 凌云县| 松江区| 宜章县| 和田市| 博客| 盘锦市| 金坛市| 元谋县| 昭平县| 沈阳市| 新郑市| 宣威市| 遂川县| 德保县| 定州市|