我繼承了Spring MVC應用程序。我熟悉.NET MVC,我想我會非常不同設計的這件事情,但我有什麼工作,這是我想做什麼:在Spring MVC應用程序中檢索會話數據
當前設計:
SearchController - 提交和呈現搜索結果。每個單獨的搜索結果都有一個添加/編輯/刪除選項,用於向不同的控制器提交請求。
@RequestMapping(valur={"/searchResult.do"}...) public ModelAndView searchResult(@ModelAttribute GlobalPojo pojo) { //here I'd like to store the pojo in session so that the search results //can be re-rendered after an Add/Edit/Delete action }
CrudController
@RequestMapping(value = { "/modifyAction.do" }, method = { org.springframework.web.bind.annotation.RequestMethod.GET }) public ModelAndView modifyRecord(@RequestParam("id") String uid) { //here I'd like to return to the results page after completing an action }
這GlobalPojo作爲參數,並導致所有的地方,所以我不能很好地使一個會話範圍豆。我想我可以做的是:
- 一下添加到SearchController:@SessionAttributes( 「searchPojo」)
- 修改@ModelAttribute - > @ModelAttribute( 「searchPojo」)
但是,我不知道該怎麼做,然後從CrudController訪問searchPojo,因爲我想在其上設置一個消息屬性以顯示在搜索結果頁面上。
我看到的將會話傳遞給控制器動作的例子不使用屬性,所以我只是不確定應該看起來像什麼。
在此先感謝。
感謝 - 我們不幸的是在3.0.5或類似的東西。但是,如果這不起作用,我會嘗試鏈接中列出的版本。 – sydneyos
@SessionAttribute方法無效(同樣,我們在早期版本中),但所提供的鏈接確實有效。也就是說,將HttpSession傳遞給控制器所涉及的動作,並在搜索動作中執行session.setAttribute,並在CRUD控制器動作中執行session.getAttribute。 – sydneyos