该期文章主要记录在线影院前端页面编写中遇到的后端逻辑BUG
{"code":"500","message":"未查询到你要修改的视频!","data":""}
public BaseResponse put_video(Video video, String token){
List<UploadVideo> uploadVideo = uploadVideoDao.get_openid(TokenUtils.getOpenid(token));
Assert.isTrue(uploadVideo.size()!=0,"未检测到你上传的视频。");
for (int i = 0; i < uploadVideo.size(); i++){
System.out.println("-----1----");
if(uploadVideo.get(i).getVid()==video.getVid()){
Assert.isTrue(videoDao.put_vid(video),"视频修改失败!");
System.out.println("-----2------");
return RespGenerator.success_noData("修改成功!");
}
}
return RespGenerator.fail("500","未查询到你要修改的视频!");
}
video实体类的vid字段为Long长整型,因为Long是long的包装类,long却是属于基本数据类型。 所以以上代码就变成了对象地址和对象地址做比较运算,故都返回false!
# 第一种:将对象转为基本数据类型再做比较
uploadVideo.get(i).getVid().longValue()==video.getVid().longValue()
# 第二种:使用xx.equals方法(xx.equals方法中也是调用xxValue方法,Integer类同理)
uploadVideo.get(i).getVid().equals(video.getVid())