亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

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

第一種:

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ù),鏈接地址上不直接暴露,但是能且只能在重定向的 “頁(yè)面” 獲取prama參數(shù)值。其原理就是放到session中,session在跳到頁(yè)面后馬上移除對(duì)象。如果是重定向一個(gè)controller中是獲取不到該prama屬性值的。除非在controller中用(@RequestPrama(value = "prama")String prama)注解,采用傳參的方式。頁(yè)面獲值例如:

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

在以上參數(shù)均可在list.jsp頁(yè)面使用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

}

  通過(guò)在controller中的list方法體中可以獲取到參數(shù)值。

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

相關(guān)文章

最新評(píng)論