开发者

SessionAttribute and SpringFramework

开发者 https://www.devze.com 2022-12-21 09:25 出处:网络
How can I set session attribute using spring framework and ann开发者_StackOverflowotation? Something equivalent to

How can I set session attribute using spring framework and ann开发者_StackOverflowotation?

Something equivalent to

 request.getSession().setAttribute("key", "value");

Thanks.


You can pass session as an attribute of controller's method and then use it directly without request.getSession(), however it isn't a big improvement and there are no annotations :)

public String handleRequest(HttpSession session) {
    session.setAttribute("key", "value");
}

EDIT:

You can also add attribute to ModelMap instance and then use @SessionAtributes annotation in these controller definitions in which you want to have that attribute inside ModelMap: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-ann-sessionattrib

0

精彩评论

暂无评论...
验证码 换一张
取 消