spring boot 读写参数到session

spring boot 读写参数到session

保存数据到session:

    @RequestMapping("/login")
    //java项目 www.fhadmin.cn
    public String login(HttpServletRequest request, @RequestParam("userName") String userName, @RequestParam("passWord") String passWord) {
        String res = userService.check_userName(userName);
        if (!res.equals("registed")) {
            return "userName has not registed";
        }    
        String str = userService.check_userName_and_passWord(userName, passWord);
        if (str.equals("success")){
            //第一步:获取session
            HttpSession session = request.getSession();
            //第二步:将想要保存到数据存入session中
            session.setAttribute("userName",userName);
            session.setAttribute("password",passWord);
            //这样就完成了用户名和密码保存到session的操作
        }
        return str;
    }
hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » spring boot 读写参数到session