我正在使用 Spring 3.2.0 MVC。我必须将一个对象存储到会话中。目前我正在使用 HttpSession 设置和获取属性来存储和检索值。
它只返回字符串而不是对象。我想在尝试使用@SessionAttribute 设置会话中的对象但我无法检索会话对象
@RequestMapping(value = "/sample-login", method = RequestMethod.POST)
public String getLoginClient(HttpServletRequest request,ModelMap modelMap) {
String userName = request.getParameter("userName");
String password = request.getParameter("password");
User user = sample.createClient(userName, password);
modelMap.addAttribute("userObject", user);
return "user";
}
@RequestMapping(value = "/user-byName", method = RequestMethod.GET)
public
@ResponseBody
String getUserByName(HttpServletRequest request,@ModelAttribute User user) {
String fas= user.toString();
return fas;
}
两种方法都在同一个控制器中。我将如何使用它来检索对象?