欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Spring RedirectAttributes參數(shù)跳轉(zhuǎn)代碼實(shí)例

 更新時間:2020年04月08日 14:21:18   作者:Erneste  
這篇文章主要介紹了Spring RedirectAttributes參數(shù)跳轉(zhuǎn)代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下

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

第一種:

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

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

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

第二種:

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

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

在以上參數(shù)均可在list.jsp頁面使用EL表達(dá)式獲取到參數(shù)值${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方法體中可以獲取到參數(shù)值。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論