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

来源:5-4 交易模型管理--交易下单03

甜甜的胖胖

2019-01-28 11:35

下单失败,debug过程中发现

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

这一句得到的userModel值为null

写回答 关注

4回答

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

    登陆失败,报空指针

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

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

    大碗稀饭 回复杭电鬼先生

    请问你现在登录session包空指针解决了吗

    2020-02-01 17:33:38

    共 2 条回复 >

  • 不知疲倦的旅者
    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中没有存入用户信息

SpringBoot构建电商基础秒杀项目

应用SpringBoot快速搭建拥有用户、商品、交易及秒杀活动的电商秒杀应用。

49540 学习 · 978 问题

查看课程

相似问题