后端生成session,并且将session保存在request里面
代码语言:javascript复制 //登录成功生成session
request.getSession().setAttribute("user",user);
String sessionId = request.getRequestedSessionId();
return R.ok().data("JSESSIONID",sessionId).data("USER",user);
代码语言:javascript复制 /**
* 从session中获取用户信息
* @return
*/
public static User getRequestUser(){
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
User user=(User)request.getSession().getAttribute("user");
return user;
}