第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

ssm怎樣在controller里面清除session

ssm怎樣在controller里面清除session

SSM
隔江千里 2018-11-12 19:04:47
ssm怎樣在controller里面清除session
查看完整描述

1 回答

?
HUH函數(shù)

TA貢獻1836條經(jīng)驗 獲得超4個贊

首先,你需要在一個Controller中往session中存內(nèi)容(取的名字必須含有大寫字母,雖然博主也不清楚為什么,如果有知道的人請一定要通知博主,博主將感激不盡):

[java] view plain copy
@Controller
@SessionAttributes("Save") //①將ModelMap中屬性名為currUser的屬性
//放到Session屬性列表中,以便這個屬性可以跨請求訪問
public class Test1Controller {
@RequestMapping("save")
public String save(Integer save,ModelMap model) {
model.addAttribute("Save",save); //②向ModelMap中添加一個屬性
return "save";
}
}
這個save數(shù)字將自動存儲在session中,name為"Save"。

如果是要在同一個controller中調(diào)用,可以這么做:
[java] view plain copy
@Controller
@SessionAttributes("Save") //①將ModelMap中屬性名為currUser的屬性
//放到Session屬性列表中,以便這個屬性可以跨請求訪問
public class <span style="font-family: Arial, Helvetica, sans-serif;">Test1Controller </span>{

@RequestMapping("save")
public String save(Integer save,ModelMap model) {
model.addAttribute("Save",save); //②向ModelMap中添加一個屬性
return "save";
}

@RequestMapping("get")
public String get(@ModelAttribute("Save") Integer save,ModelMap model) {
System.out.println("save:"+save); //modelMap中的Save將自動綁定在save上
return "get";
}
}
我們即可在get中獲得了保存在session中的Save對象

如果是要在其他controller中調(diào)用,可以這么做
[java] view plain copy
@Controller
@SessionAttributes("Save") //①將ModelMap中屬性名為currUser的屬性
//放到Session屬性列表中,以便這個屬性可以跨請求訪問
public class <span style="font-family: Arial, Helvetica, sans-serif;">Test2Controller </span>{

@RequestMapping("get")
public String get(@ModelAttribute("Save") Integer save,ModelMap model) {
System.out.println("save:"+save); //modelMap中的Save將自動綁定在save上
return "get";
}
}

方式相同,但需記住,即使你不使用modelMap,仍需注入該對象,方法中仍需保留該參數(shù),切記??!



查看完整回答
反對 回復(fù) 2018-11-15
  • 1 回答
  • 0 關(guān)注
  • 1543 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號