Java tutorial
/* * Copyright(C) 2014 * NEC Corporation All rights reserved. * * No permission to use, copy, modify and distribute this software * and its documentation for any purpose is granted. * This software is provided under applicable license agreement only. */ package com.nec.harvest.resolver; import org.springframework.core.MethodParameter; import org.springframework.web.bind.support.WebDataBinderFactory; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.context.request.WebRequest; import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.ModelAndViewContainer; import com.nec.harvest.stereotype.SessionAttribute; public class SessionArgumentResolver implements HandlerMethodArgumentResolver { @Override public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { final SessionAttribute attr = parameter.getParameterAnnotation(SessionAttribute.class); return webRequest.getAttribute(attr.value(), WebRequest.SCOPE_SESSION); } @Override public boolean supportsParameter(MethodParameter parameter) { return parameter.getParameterAnnotation(SessionAttribute.class) != null; } }