控制器中设值部分:
@PostMapping(value="/userLogin") public ModelAndView login(String uname,String pswd,HttpSession httpSession) { User user=userService.searchUserByNamePswd(uname, pswd); if(user!=null) { httpSession.setAttribute("user", user); logger.info("Now User:{} logged in.",user.getName()); return new ModelAndView("blank"); }else { ModelAndView mav=new ModelAndView("login"); mav.addObject("errMsg", "用户名或密码有误."); return mav; } }
页面上取值部分:
<span th:text="${session.user.name}">user name</span>
END