添加按照分数降序排序
This commit is contained in:
parent
64afc10223
commit
8fc08dad6a
|
@ -11,6 +11,7 @@ import com.example.catchTheLetters.utils.R;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Pageable;
|
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.MongoTemplate;
|
||||||
import org.springframework.data.mongodb.core.query.Criteria;
|
import org.springframework.data.mongodb.core.query.Criteria;
|
||||||
import org.springframework.data.mongodb.core.query.Query;
|
import org.springframework.data.mongodb.core.query.Query;
|
||||||
|
@ -132,7 +133,7 @@ public class LevelServiceImpl implements LevelService {
|
||||||
@Override
|
@Override
|
||||||
public ScoreInfoPage getScoreInfo(String levelId, Integer page, Integer size) {
|
public ScoreInfoPage getScoreInfo(String levelId, Integer page, Integer size) {
|
||||||
long total = mongoTemplate.count(new Query(),ScoreInfo.class)/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);
|
List<ScoreInfo> scores = mongoTemplate.find(new Query(Criteria.where("levelId").is(levelId)).with(pageable), ScoreInfo.class);
|
||||||
return new ScoreInfoPage(scores,total);
|
return new ScoreInfoPage(scores,total);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue