2012-04-15 7 views
2

これは、2つのSpring 3コントローラ間でセッションを共有することに関する質問です。コントローラのセッション属性を別のコントローラから削除する方法はありますか?

1つのコントローラがエンティティの表示を処理します。 @SessionAttributesにデータベース選択結果をキャッシュします。別のコントローラはエンティティの追加と削除を処理します。課題は、第2のコントローラがエンティティを追加または削除するときはいつでも、第1のコントローラのセッションキャッシュを削除することである。

インデックスコントローラ

@Controller 
@RequestMapping(value="/fileIndex") 
@SessionAttributes(value={IndexController.INDEX_ITEM_LIST}) 
public class FileIndexController extends IndexController { 

if(!model.containsAttribute(IndexController.INDEX_ITEM_LIST)) { 
    model.addAttribute(IndexController.INDEX_ITEM_LIST, getFileList(screenObject)); // sql select 
} 
screenObject.setPageItemList((List<?>) model.asMap().get(IndexController.INDEX_ITEM_LIST), pageNumber); // page of entities (subset of cached sql select) 

アクションコントローラ - 削除方法

@RequestMapping(method=RequestMethod.POST, params=ACTION_DELETE) 
public ModelAndView delete(@ModelAttribute("screenObject") FileHeaderEditScreenObject screenObject, BindingResult bindingResult, Model model, Locale locale) { 

    try { 
     fileService.deleteFile(screenObject.getFileId()); 
    } catch(Throwable t) { 
     screenObject.addError(t.getMessage()); 
    } 

    ModelAndView modelAndView=new ModelAndView(); 
    if(screenObject.getErrorCount()>0) { 
     initializeScreenObject(screenObject.getFileId(), screenObject, locale, false); 
     modelAndView.setViewName(WebView.FILE_HEADER_EDIT_PAGE.getViewName()); 
    } else { 
     modelAndView.setViewName("redirect:/fileIndex"); 
    } 
    model.asMap().remove(IndexController.INDEX_ITEM_LIST); // this does not work 
    return modelAndView; 
} 

答えて

0

あなたはSessionStatus.setComplete()を使用することができます。

関連する問題