基本上,
session注入到 Spring MVC 控制器中的对象之间没有区别:
@RequestMapping(value = "/somepath", method = RequestMethod.POST)@ResponseBodypublic JsonResponse someMethod (HttpSession session){ // play with session attributes}以及
session从中检索的对象
HttpServletRequest:
@RequestMapping(value = "/somepath", method = RequestMethod.POST)@ResponseBodypublic JsonResponse someMethod (HttpServletRequest request){ Session session = request.getSession(); // You are playin with the same session attributes.}前一种样式只是
HttpSession通过将其作为控制器参数注入而为您提供了获取上下文对象的便利,以便 Spring 可以为您处理所有脏东西。



