1

我有一个像这样的课程:

@Controller(value = "services")
@RequestMapping("/")
@SessionAttributes({"SESSIONID"})
public class Services {

   @RequestMapping("/user/loginStatic")
   @ModelAttribute("SESSIONID")
   public LoginResponseBean loginStatic(String username){
       LoginResponseBean result = otherClass.login(username);
       retrun result;
   }
}

我的问题:这段代码导致在会话中存储“结果”对象,但我想在会话中存储“result.getSessionId()”。

我不能将“模型模型”添加到“loginStatic”方法的输入参数,因为它会改变方法的签名,我现在不能这样做。而且我无法明确获取http会话并在其中设置属性(因为其他一些副作用)。我怎么能那样做?谢谢..

4

2 回答 2

1

您可以使用<mvc:interceptors/>注册HandlerInterceptor适用于一个、多个或所有控制器的自定义。例如,这里是如何为所有控制器注册一个拦截器:

<mvc:interceptors>
    <mvc:interceptor>
        <mvc:mapping path="/**"/>
        <bean class="a.b.c.MyHandlerInterceptorAdapter"/>
    </mvc:interceptor>
</mvc:interceptors>

mvc-config-interceptors另请参阅mvc-handlermapping-interceptor文档以获取更多详细信息。

注意:Spring 3.2 文档已链接,因此您可能需要更改 URL 中的版本号以匹配您使用的 Spring 版本。

于 2013-01-09T08:54:03.223 回答
0

在这里查看接受的答案: 如何在春季获取会话对象

您可以按照那里的描述获取会话对象并添加您的属性。

于 2013-01-09T07:39:54.533 回答