设置session的过期时间
1 2 3 4
| server: servlet: session: timeout: PT5H
|
其中T是天和小时的分界符,不区分大小写,时间必须按顺序
比如说 P2dt5h3m30s
就是两天五小时三分钟三十秒
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| @PostMapping("/user/login") public ResponseVO<User> login(@Valid @RequestBody UserLoginForm userLoginForm, BindingResult bindingResult, HttpServletRequest httpServletRequest){ if(bindingResult.hasErrors()){ return ResponseVO.error(ResponseEnum.PARAM_ERROR,bindingResult);
}
ResponseVO<User> responseVO = userService.login(userLoginForm.getUsername(), userLoginForm.getPassword());
HttpSession session = httpServletRequest.getSession(); session.setAttribute(MallConst.CURRENT_USER,responseVO.getData());
return responseVO;
}
|
还有另外一种获取方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| @PostMapping("/user/login") public ResponseVO<User> login(@Valid @RequestBody UserLoginForm userLoginForm, BindingResult bindingResult, HttpSession session){ if(bindingResult.hasErrors()){ return ResponseVO.error(ResponseEnum.PARAM_ERROR,bindingResult);
}
ResponseVO<User> responseVO = userService.login(userLoginForm.getUsername(), userLoginForm.getPassword());
session.setAttribute(MallConst.CURRENT_USER,responseVO.getData());
return responseVO;
}
|