为什么我的数据库参入name显示为false(这边的那么我用nick代替)

来源:3-11 用户模型管理--用户注册功能实现02

慕后端8268368

2019-07-06 20:03

https://img2.mukewang.com/5d208df00001bafe06490069.jpg

求帮忙解答,谢谢

写回答 关注

2回答

  • 慕后端8268368
    2019-07-07 08:40:26

    进行用户注册,能够成功的注册,但是Nick列显示的总是false。以下是我的代码:

    //service代码
    @Override
    @Transactional//事务提交,防止出错
    public void register(UserModel userModel) throws BusinessException {
        if(userModel==null){
            throw new BusinessException(EmBussinessError.PARAMETER_VALIDATION_ERROR,"对象为空");
        }
       if(StringUtils.isEmpty(userModel.getNick())||userModel.getGender()==null||
       userModel.getAge()==null||StringUtils.isEmpty(userModel.getTelphone())){
           throw new BusinessException(EmBussinessError.PARAMETER_VALIDATION_ERROR,"入参不合法");
       }
       UserDO userDO=convertFromUserModel(userModel);//实现model到dataobject方法;
       userDOMapper.insertSelective(userDO);
       userModel.setId(userDO.getId());
       UserPasswordDO userPasswordDO=convertPasswprdFromModel(userModel);//实现model到dataobject
        userPasswordDOMapper.insertSelective(userPasswordDO);
    
       return;
    }
    //将model转化为userDo
    public UserDO convertFromUserModel(UserModel userModel){
        if(userModel==null){
            return null;
        }
        UserDO userDO=new UserDO();
        BeanUtils.copyProperties(userModel,userDO);
        return userDO;
    }
    //获取password信息
    private UserPasswordDO convertPasswprdFromModel(UserModel userModel){
        if(userModel==null){
            return null;
        }
        UserPasswordDO  userPasswordDO=new UserPasswordDO();
        userPasswordDO.setEncrptpassword(userModel.getEncrptpassword());
        userPasswordDO.setUserId(userModel.getId());
        return userPasswordDO;
    }
    
    //controller代码 
    //用户注册接口
    @RequestMapping(value = "/register",method = {RequestMethod.POST},consumes = {CONTENT_TYPE_FORMED})//获得个头图片的映射
    @ResponseBody
    public CommonReturnType register(@RequestParam(name="telphone")String telphone,
                                     @RequestParam(name="otpCode")String otpCode,
                                     @RequestParam(name="nick")String nick,
                                     @RequestParam(name="gender")String gender,
                                     @RequestParam(name="age")Integer age,
                                     @RequestParam(name="password")String password) throws BusinessException, UnsupportedEncodingException, NoSuchAlgorithmException {
        //验证手机号和对应的otpcode相符合
        String insessionOtpCode= (String) this.httpServletRequest.getSession().getAttribute(telphone);
        if(!StringUtils.equals(otpCode,insessionOtpCode)){
            throw new BusinessException(EmBussinessError.PARAMETER_VALIDATION_ERROR,"短信验证码不正确");
        }
    
        //用户的注册流程
        UserModel userModel=new UserModel();
        userModel.setNick(nick);
        userModel.setGender(gender);
        userModel.setAge(age);
        userModel.setTelphone(telphone);
        userModel.setEncrptpassword(this.EncodeByMd5(password));
    
        userService.register(userModel);
        return CommonReturnType.create(null);
    }

  • 慕圣9164412
    2019-07-06 23:43:42

    描述清楚一点

    慕后端826...

    我检查过代码,好像没有错误,下面是我的代码,请查看,谢谢

    2019-07-07 08:41:42

    共 1 条回复 >

SpringBoot构建电商基础秒杀项目

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

49065 学习 · 954 问题

查看课程

相似问题