添加按照分数降序排序

This commit is contained in:
ETHEREAL 2024-06-13 11:15:21 +08:00
parent 64afc10223
commit 8fc08dad6a
1 changed files with 2 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import com.example.catchTheLetters.utils.R;
import jakarta.annotation.Resource;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
@ -132,7 +133,7 @@ public class LevelServiceImpl implements LevelService {
@Override
public ScoreInfoPage getScoreInfo(String levelId, Integer page, Integer size) {
long total = mongoTemplate.count(new Query(),ScoreInfo.class)/size;
Pageable pageable = PageRequest.of(page - 1, size);
Pageable pageable = PageRequest.of(page - 1, size, Sort.Direction.DESC,"score");
List<ScoreInfo> scores = mongoTemplate.find(new Query(Criteria.where("levelId").is(levelId)).with(pageable), ScoreInfo.class);
return new ScoreInfoPage(scores,total);
}