Skip to content

Commit 71dc559

Browse files
author
YXJ2018
committed
分数页面增加分页
1 parent f48f972 commit 71dc559

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

springboot/src/main/java/com/exam/controller/ScoreController.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.exam.controller;
22

3+
import com.baomidou.mybatisplus.core.metadata.IPage;
4+
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
35
import com.exam.entity.ApiResult;
6+
import com.exam.entity.Message;
47
import com.exam.entity.Score;
58
import com.exam.serviceimpl.ScoreServiceImpl;
69
import com.exam.util.ApiResultHandler;
@@ -20,14 +23,11 @@ public ApiResult findAll() {
2023
return ApiResultHandler.buildApiResult(200,"查询所有学生成绩",res);
2124
}
2225

23-
@GetMapping("/score/{studentId}")
24-
public ApiResult findById(@PathVariable("studentId") Integer studentId) {
25-
List<Score> res = scoreService.findById(studentId);
26-
if (!res.isEmpty()) {
27-
return ApiResultHandler.buildApiResult(200,"根据ID查询成绩",res);
28-
}else {
29-
return ApiResultHandler.buildApiResult(400,"ID不存在",res);
30-
}
26+
@GetMapping("/score/{page}/{size}/{studentId}")
27+
public ApiResult findById(@PathVariable("page") Integer page, @PathVariable("size") Integer size, @PathVariable("studentId") Integer studentId) {
28+
Page<Score> scorePage = new Page<>(page, size);
29+
IPage<Score> res = scoreService.findById(scorePage, studentId);
30+
return ApiResultHandler.buildApiResult(200, "根据ID查询成绩", res);
3131
}
3232

3333
@PostMapping("/score")

springboot/src/main/java/com/exam/mapper/ScoreMapper.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.exam.mapper;
22

3+
import com.baomidou.mybatisplus.core.metadata.IPage;
4+
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
35
import com.exam.entity.Score;
46
import org.apache.ibatis.annotations.Insert;
57
import org.apache.ibatis.annotations.Mapper;
@@ -18,11 +20,11 @@ public interface ScoreMapper {
1820
@Insert("insert into score(examCode,studentId,subject,ptScore,etScore,score,answerDate) values(#{examCode},#{studentId},#{subject},#{ptScore},#{etScore},#{score},#{answerDate})")
1921
int add(Score score);
2022

21-
@Select("select scoreId,examCode,studentId,subject,ptScore,etScore,score,answerDate from score")
23+
@Select("select scoreId,examCode,studentId,subject,ptScore,etScore,score,answerDate from score order by scoreId desc")
2224
List<Score> findAll();
2325

24-
@Select("select scoreId,examCode,studentId,subject,ptScore,etScore,score,answerDate from score where studentId = #{studentId}")
25-
List<Score> findById(Integer studentId);
26+
@Select("select scoreId,examCode,studentId,subject,ptScore,etScore,score,answerDate from score where studentId = #{studentId} order by scoreId desc")
27+
IPage<Score> findById(Page<?> page, Integer studentId);
2628

2729
/**
2830
*

springboot/src/main/java/com/exam/service/ScoreService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.exam.service;
22

3+
import com.baomidou.mybatisplus.core.metadata.IPage;
4+
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
35
import com.exam.entity.Score;
46

57
import java.util.List;
@@ -9,7 +11,7 @@ public interface ScoreService {
911

1012
List<Score> findAll();
1113

12-
List<Score> findById(Integer studentId);
14+
IPage<Score> findById(Page page, Integer studentId);
1315

1416
List<Score> findByExamCode(Integer examCode);
1517
}

springboot/src/main/java/com/exam/serviceimpl/ScoreServiceImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.exam.serviceimpl;
22

3+
import com.baomidou.mybatisplus.core.metadata.IPage;
4+
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
35
import com.exam.entity.Score;
46
import com.exam.mapper.ScoreMapper;
57
import com.exam.service.ScoreService;
@@ -24,8 +26,8 @@ public List<Score> findAll() {
2426
}
2527

2628
@Override
27-
public List<Score> findById(Integer studentId) {
28-
return scoreMapper.findById(studentId);
29+
public IPage<Score> findById(Page page, Integer studentId) {
30+
return scoreMapper.findById(page, studentId);
2931
}
3032

3133
@Override

0 commit comments

Comments
 (0)