问答详情
源自:5-4 交易模型管理--交易下单03

空指针错误,获取登录信息userModel值为null

下单失败,debug过程中发现

UserModel userModel=(UserModel)httpServletRequest.getSession().getAttribute("LOGIN_USER");

这一句得到的userModel值为null

提问者:甜甜的胖胖 2019-01-28 11:35

个回答

  • weixin_慕慕9502449
    2019-08-03 10:43:39

    登陆失败,报空指针

  • 甜甜的胖胖
    2019-01-30 09:06:05

     找到问题了,validateLogin方法里返回值应该是userModel,老师的视频里直接写的是return;

  • 不知疲倦的旅者
    2019-01-29 19:55:40

    在登录请求中把用户的信息存储到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);
    
    }


  • 李菜菜
    2019-01-29 15:21:39

    未登录,session中没有存入用户信息