本篇內容介紹了“Spring RedirectAttributes如何實現參數跳轉的方法”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
成都創新互聯專業為企業提供徐州網站建設、徐州做網站、徐州網站設計、徐州網站制作等企業網站建設、網頁設計與制作、徐州企業網站模板建站服務,十余年徐州做網站經驗,不只是建網站,更提供有價值的思路和整體網絡服務。
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 RedirectAttributes如何實現參數跳轉的方法”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注創新互聯網站,小編將為大家輸出更多高質量的實用文章!
分享標題:SpringRedirectAttributes如何實現參數跳轉的方法
網頁鏈接:http://vcdvsql.cn/article2/jhehoc.html
成都網站建設公司_創新互聯,為您提供App設計、網頁設計公司、網站建設、、小程序開發、網站營銷
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯