@RequestMapping(value = "/loginUser", produces = {"text/html;charset=utf-8"}, method = RequestMethod.POST) public String login(@RequestParam(value = "user", required = false) String user, @RequestParam(value = "password") String password, @RequestParam(value = "telephone") String telephone, HttpSession session) { 。。。。。。省略一大段代码 //这里设置一下session,保存登录的用户信息到session中去 session.setAttribute("user",userDO); } 获取session。 /** * 登录的时候进到主页面 * @return */ @RequestMapping("/") public ModelAndView requestMapping(HttpSession session) { ModelAndView map = new ModelAndView("index"); System.out.println(session.getAttribute("user")); userMapper userMapper = (userMapper)session.getAttribute("user"); if(userMapper!=null) map.addObject("userid", userMapper.getUserid()); return map; }