2013년 1월 30일 수요일

@SessionAttribute

@SessionAttribute관련하여 구글링하여 들어간 어느 블로그에 OLC(Open software Learning Cummunity)이 소개되어 있서 거기에 가입하고, 백기선, 이일민씨 등 프레임워크 구루의 강의가 있어 다 들었다. 후에 이들이 전자전부프레임워크 커뮤니티의 커미터라는 얘기에 또 거기 뒤적거리다가 해당 블로그로 돌아왔다. 하여간 관심사가 많은 것도 문제다. 또 여러 개발관련 커뮤니티를 돌아본 뒤 느낀건 나에겐 그런 다양하고 방대한 내용의 개발지식을 다 소화할 수 있는 열정과 능력이 있나. 없다면 유능한 개발자가 될 수 있을까라는 회의가 든다.

'쉽게 따라하는 자바 웹개발'의 p.138을 정리하면, @SessionAttributes의 정의를 이렇게 내릴 수 있다. 빈에서 @SessionAttributes("애트리뷰트명")로 선언하면, 해당 애트리뷰트명으로 Model에 어떤 값이 들어가면 그 값(객체)을 세션에 담아둔다. 언제까지? 그 세션에 담아둔 객체를 비울 때 (complete)때까지.

아래는 스프링 reference에 있는 @SessionAttributes 정의다.


15.3.2.9 Specifying attributes to store in a session with @SessionAttributes

The type-level @SessionAttributes annotation declares session attributes used by a specific handler. This will typically list the names of model attributes or types of model attributes which should be transparently stored in the session or some conversational storage, serving as form-backing beans between subsequent requests.
The following code snippet shows the usage of this annotation, specifying the model attribute name:

@SessionAttributes 애노테이션은 하나의 특정 핸들러에 의해 사용되는 세션 어트리뷰트를 선언한다. 이것은 일반적으로 모델 애트리뷰트 또는 모델 애트리뷰트 타입의 이름이다. 그 애트리뷰트는 세션이나 conversational한 저장소에 유연하게 저장된다. 그리고 그 애트리뷰트는 이후 요청들간에 form-backing 빈으로 작동한다.
다음의 코드정보는 이 애노테이션의 사용이 모델 애트리뷰트명을 지칭하는 것을 보여준다.

@Controller
@RequestMapping("/editPet.do")
@SessionAttributes("pet")
public class EditPetForm {
    // ...
}
[Note]Note
When using controller interfaces (e.g. for AOP proxying), make sure to consistently put all your mapping annotations - such as@RequestMapping and @SessionAttributes - on the controller interface rather than on the implementation class.

댓글 없음 :

댓글 쓰기