求和一下高三年级在某个时间段的的各科成绩的总和数,,要求多添加一条数据显示各科成绩的总数,比如:数学 : (数学成绩的总和)这样
先是用for循环得出各科的成绩
List<ScoreVO> scoreVOList = new ArrayList<>;//定义的返回对象列表
LambdaQueryWrapper<Score> wrapper = Wrappers.<Score>lambdaQuery;
List<Score> scoreList = querySoreDataMapper.selectList(wrapper);
for(int i = 1; i < scoreList.size(); i++){
Score scoreData = scoreList.get(i);
ScoreVO score = new ScoreVO();
score.setMath(scoreData.getMath());
....
....
....
scoreVOList.add(score);
}
//这里添加一条数据,用来显示各科成绩总和数据
ScoreVO all = new ScoreVO();
scoreVOList.add(all);
for(int i = 0; i < scoreVOList.szie(); i++){
ScoreVO item = scoreVOList.get(i);
all.setMath(all.getMath+item.getMath);
...
...
...
}
//对数据进行排序后返回
List<ScoreVO> collect = scoreVOList.stream().sorted(Comparator.comparing(ScoreVO :: getMath, new Comparator<Long>(){
})).collect(Collectors.toList());
return collect;
}
最后返回的时候,各科成绩的最终数,都变成了两倍
比如说,Math,也就是数学成绩,原本计算下来应该是5200分,但是最后返回的却是14000分,变成了两倍
怎么解???