java 获取session值(简单易懂)

java 获取session值

首先看怎么去存

@RequestMapping("/login")
    public String login(String username, String password, Model model, HttpSession session)

controller上写HttpSession session

session.setAttribute("count", count);
session.setAttribute("user",user);

然后怎么获取

@RequestMapping("/find")
    public String findAll(Model model,HttpServletRequest request)

在请求上添加HttpServletRequest request

 //获取session
        HttpSession  session = request.getSession();
session有以下方法
session.getAttributeNames()
session.getCreationTime() 
session.getAttribute("user")
用他们去满足你的需求

上面的项目源码
github地址:https://github.com/zhoushibo-111/SSMairuiqiwebsite
或者
https://gitee.com/zhoushiwangchao/SSMairuiqiwebsite

你可能感兴趣的:(java,session,spring)