为了账号安全,请及时绑定邮箱和手机立即绑定

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

https://img1.sycdn.imooc.com//5d208df00001bafe06490069.jpg

求帮忙解答,谢谢

正在回答

2 回答

进行用户注册,能够成功的注册,但是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);
}

0 回复 有任何疑惑可以回复我~

描述清楚一点

0 回复 有任何疑惑可以回复我~
#1

慕后端8268368 提问者

我检查过代码,好像没有错误,下面是我的代码,请查看,谢谢
2019-07-07 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

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

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信