session.setAttribute(Const.CURRENT_USER,response.getData());
来源:6-7 更新用户个人信息功能开发

空度啊
2018-04-02
User updateUser=new User();
updateUser.setId(user.getId());
updateUser.setEmail(user.getEmail());
updateUser.setPhone(user.getPhone());
updateUser.setQuestion(user.getQuestion());
updateUser.setAnswer(user.getAnswer());
int updateCount=userMapper.updateByPrimaryKeySelective(updateUser);
if(updateCount>0){
return ServerResponse.createBySuccess("更新个人信息成功",updateUser);
}
return ServerResponse.createByErrorMessage("更新个人信息失败");User currentUser=(User)session.getAttribute(Const.CURRENT_USER);
if(currentUser==null){
return ServerResponse.createByErrorMessage("用户未登录");
}
//user从前端传递过来时无userid,防止越权,从前端传过来的id被改变,从而改变别的user数据
user.setId(currentUser.getId());
user.setUsername(currentUser.getUsername());
//将返回的updateuser放入response对象中
ServerResponse<User> response=iUserService.updateInformation(user);
if(response.isSuccess()){
response.getData().setUsername(currentUser.getUsername());
session.setAttribute(Const.CURRENT_USER,response.getData());
}
return response;
老师,这样把updateUser给注入到session中,那么session中的Const.CURRENT_USER不就没有role值了?这跟currentUser不就不一样了吗?而且也没有password字段了,这样没关系吗?
2回答
-
没有password字段是因为不显示返回给前端,以免被爬取到,role值如果没有你可以自己再注入
00 -
Geely
2018-04-05
如菠萝同学所说,是这样的,密码肯定不能返回的,整体都是出于安全考虑。
00
相似问题