//这个是登录方法 是可以用的
@RequestMapping(value = “/login“,method = RequestMethod.POST)
public String testLogin(HttpServletRequest request,@RequestParam String username, @RequestParam String password) {
log.info(“执行了testLogin方法!”);
User user = userService.findUserByName(username);
if(user!=null){;
if(user.getPassword().equals(DigestUtils.md5Hex(password))){
request.getSession().setAttribute(“userId”, user.getId());
request.getSession().setAttribute(“user”, username);
return “redirect:” + RequestUtil.retrieveSavedRequest();//跳转至访问页面
}else{
log.info(“密码错误”);
request.getSession().setAttribute(“message”, “用户名密码错误,请重新登录”);
return “login“;
}
}else{
log.info(“用户名不存在”);
request.getSession().setAttribute(“message”, “用户名不存在,请重新登录”);
return “login“;
}
}
@RequestMapping(value = “/loginout”,method = RequestMethod.GET)
public String signOut() {
log.info(“返回首页!”);
//请问退出,比如页面点击了退出按钮超链接到这方法,怎么弄呢?怎么写?
return “login“;
}
@ResponseBody @RequestMapping("/logout") public String logout(HttpServletRequest request){ HttpSession session=request.getSession(); session.setAttribute("user", null); return "login"; }
把session的用户数据清空,再跳回登录页面就好了
也可以remove掉