Spring MVC custom scope bean

前端 未结 3 1754
时光取名叫无心
时光取名叫无心 2020-12-03 02:09

I would like to create my own custom scope bean which will use HTTP session (kind of Flash scope).

According to Spring Manual I need to implement org.springframewor

3条回答
  •  感动是毒
    2020-12-03 02:47

    You can get access to session attributes using the next code within your scope class methods in Spring MVC (works in 3.2):

    RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
    attributes.getAttribute("some key", NativeWebRequest.SCOPE_SESSION);
    attributes.setAttribute("some key", YouObject, NativeWebRequest.SCOPE_SESSION);
    

    RequestAttributes implementation (ServletRequestAttributes) internally will call set/getAttribute() methods on current session object.

提交回复
热议问题