甜甜的胖胖
2019-01-28 11:35
下单失败,debug过程中发现
UserModel userModel=(UserModel)httpServletRequest.getSession().getAttribute("LOGIN_USER");这一句得到的userModel值为null
登陆失败,报空指针
找到问题了,validateLogin方法里返回值应该是userModel,老师的视频里直接写的是return;
在登录请求中把用户的信息存储到session中
@PostMapping("/login")
public CommonReturnType login(@RequestParam(value = "telephone") String telephone,
@RequestParam(value = "password") String password) throws BusinessException, UnsupportedEncodingException, NoSuchAlgorithmException {
//入参校验
if (StringUtils.isEmpty(telephone) || StringUtils.isEmpty(password)) {
throw new BusinessException(EnumBussinessError.PARAMETER_VALIDATION_ERROR);
}
//用户登录校验,校验登录是否合法
UserModel userModel = userService.validateLogin(telephone, this.encodeByMD5(password));
//将登录凭证加入到用户登录成功的session内
request.getSession().setAttribute("IS_LOGIN", true);
request.getSession().setAttribute("LOGIN_USER", userModel);
return CommonReturnType.create(null);
}
未登录,session中没有存入用户信息
SpringBoot构建电商基础秒杀项目
49540 学习 · 978 问题
相似问题