基于javaweb的SpringBoot微服务SpringCloud在线考试系统(java+springboot+springcloud+mysql+maven)

运行环境

Java≥8、MySQL≥5.7

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

482024331009

540123022402

550123022402

560123022402

570123022402

580123022402

590123022402

221025280401

基于javaweb的SpringBoot微服务SpringCloud在线考试系统(java+springboot+springcloud+mysql+maven)

考试流程:

用户前台注册成为学生

管理员后台添加老师,系统将该用户角色上升为老师

老师登录,添加考试,添加题目,发布考试

考生登录前台参加考试,交卷

老师后台批改试卷,查看成绩

考试查看成绩

练习流程:

考生登录前台参加练习,练习完自动判分,记录错题

考生查看成绩,查看错题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
    answerQuestion.setType(question.getType());
answerQuestion.setNumber(question.getNumber());
answerQuestion.setOptionA(question.getOptionA());
answerQuestion.setOptionB(question.getOptionB());
answerQuestion.setOptionC(question.getOptionC());
answerQuestion.setOptionD(question.getOptionD());
answerQuestion.setContent(question.getContent());
answerQuestion.setScore(question.getScore());
answerQuestion.setAnalysis(question.getAnalysis());
answerQuestion.setAnswer(question.getAnswer());


answerPaperQuestion = new AnswerPaperQuestion();
answerPaperQuestion.setAnswerPaperId(answerPaper.getId());
answerPaperQuestion.setAnswerQuestionId(answerQuestionId);

//保存
answerQuestionService.saveAnswerQuestion(answerQuestion);
answerPaperQuestionService.saveAnswerPaperQuestion(answerPaperQuestion);

return new ResponseEntity<Object>(answerPaper, HttpStatus.OK);
} else {
answerQuestions = answerQuestionService.findByAnswerPaperId(answerPaper.getId());
if(answerQuestions != null && answerQuestions.size() > 0) {
int count = 0;
AnswerQuestion existAnswerQuestion = null;
for(AnswerQuestion question1 : answerQuestions) {
if (question1.getNumber().equals(question.getNumber())) {
count++;
existAnswerQuestion = question1;//保存当前存在的记录
}
}
//记录不存在
if(count == 0) {
//新记录
answerQuestion = new AnswerQuestion();
answerPaperQuestion = new AnswerPaperQuestion();


answerQuestion = new AnswerQuestion();
//初始化信息
answerQuestion.setId(answerQuestionId);
answerQuestion.setTitle(question.getTitle());
answerQuestion.setType(question.getType());
answerQuestion.setNumber(question.getNumber());
answerQuestion.setOptionA(question.getOptionA());
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
                                                  @PathVariable Integer number,
@RequestParam(required = false) String answerPaperId) {
PaperAnswerPaper paperAnswerPaper = null;
//传入的是答卷Id
if(answerPaperId != null) {
paperAnswerPaper = paperAnswerPaperService.getByAnswerPaperId(answerPaperId);
if(paperAnswerPaper != null) {
return questionService.getQuestionByPaperIdAndQuestionNumber(paperAnswerPaper.getPaperId(), number);
}else {
logger.error("根据答卷id获取答卷失败");
}
}
return questionService.getQuestionByPaperIdAndQuestionNumber(paperId, number);
}

@ApiOperation(value = "获取题目信息", notes = "根据题目name获取题目详细信息")
@ApiImplicitParam(name = "name", value = "试卷name", required = true, dataType = "String", paramType = "path")
@RequestMapping(value = "/name/{name}", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "') or hasAuthority('" + Role.ROLE_STUDENT + "')")
public List<Question> getQuestionByName(@PathVariable String name) {
//模糊查询
return questionService.getQuestionFuzzy(name);
}

@ApiOperation(value = "获取题目信息", notes = "根据试卷id获取所有题目")
@ApiImplicitParam(name = "paperId", value = "试卷ID", required = true, dataType = "String", paramType = "path")
@RequestMapping(value = "/papers/{paperId}/questions", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "') or hasAuthority('" + Role.ROLE_STUDENT + "')")
public List<Question> getQuestionByPaperId(@PathVariable String paperId) {
return questionService.getQuestionByPaperId(paperId);
}

@ApiOperation(value = "获取题目信息", notes = "根据试卷id获取所有题目,但不返回答案")
@ApiImplicitParam(name = "paperId", value = "试卷ID", required = true, dataType = "String", paramType = "path")
@RequestMapping(value = "/papers/{paperId}/ignore", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "') or hasAuthority('" + Role.ROLE_STUDENT + "')")
public List<Question> getQuestionByPaperIdIgnoreAnswer(@PathVariable String paperId) {
return questionService.getQuestionByPaperIdIgnoreAnswer(paperId);
}

@ApiOperation(value = "更新题目信息", notes = "根据题目id更新题目信息")
@ApiImplicitParam(name = "question", value = "题目实体", required = true, dataType = "Question")
@RequestMapping(value = "", method = RequestMethod.PUT)
@PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "')")
public ResponseEntity<?> putQuestion(@RequestBody Question question) {
questionService.updateQuestion(question);
return new ResponseEntity(HttpStatus.OK);
}

@ApiOperation(value = "删除题目", notes = "根据题目id删除试卷")
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    })
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
@PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "')")
public ResponseEntity<?> putTeacher(@PathVariable String id, @RequestBody Teacher teacher) {
teacherService.updateTeacher(teacher);
return new ResponseEntity(HttpStatus.OK);
}

@ApiOperation(value = "删除教师", notes = "根据教师id删除教师")
@ApiImplicitParam(name = "id", value = "教师ID", required = true, dataType = "String", paramType = "path")
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
@PreAuthorize("hasAuthority('" + Role.ROLE_ADMIN + "')")
public ResponseEntity<?> deleteTeacher(@PathVariable String id) {
teacherService.deleteTeacher(id);
return new ResponseEntity(HttpStatus.OK);
}
}

package com.tangyi.web;



/**
*/
@RestController
@RequestMapping(value = "/v1/subjects")
public class SubjectController {

private static Logger logger = LoggerFactory.getLogger(SubjectController.class);

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
    return pageInfo;
}

@ApiOperation(value = "新增教师", notes = "新增教师")
@ApiImplicitParam(name = "teacher", value = "教师实体teacher", required = true, dataType = "Teacher")
@RequestMapping(value = "", method = RequestMethod.POST)
@PreAuthorize("hasAuthority('" + Role.ROLE_ADMIN + "')")
public ResponseEntity<?> postTeacher(@RequestBody Teacher teacher) {
/**
* 1.已经注册
* 2.不能重复添加
* 3.分配权限
*/
MapperUser user = userService.getUserByName(teacher.getTeacherName());
if(user != null && teacherService.getTeacherByName(teacher.getTeacherName()) == null) {
//绑定id
teacher.setId(user.getId());
teacherService.saveTeacher(teacher);
}else {
return new ResponseEntity(HttpStatus.BAD_REQUEST);
}
return new ResponseEntity(HttpStatus.CREATED);
}

@ApiOperation(value = "根据名字获取教师信息", notes = "根据教师名字获取教师详细信息")
@ApiImplicitParam(name = "name", value = "教师名字", required = true, dataType = "String", paramType = "path")
@RequestMapping(value = "/{name}/name", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "')")
public List<Teacher> getTeacherByName(@PathVariable String name) {
return teacherService.getTeacherFuzzy(name);
}

@ApiOperation(value = "获取教师信息", notes = "根据教师id获取教师详细信息")
@ApiImplicitParam(name = "id", value = "教师ID", required = true, dataType = "String", paramType = "path")
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "')")
public Teacher getTeacherById(@PathVariable String id) {
return teacherService.getTeacherById(id);
}

@ApiOperation(value = "获取教师班级信息", notes = "根据教师name获取班级详细信息")
@ApiImplicitParam(name = "name", value = "教师name", required = true, dataType = "String", paramType = "path")
@RequestMapping(value = "/name/grade/{name}", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "')")
public List<Grade> getGradeByTeacher(@PathVariable String name) {
return teacherService.findGradeByName(name);
}

@ApiOperation(value = "获取教师学生信息", notes = "根据教师name获取学生详细信息")
@ApiImplicitParam(name = "name", value = "教师name", required = true, dataType = "String", paramType = "path")
@RequestMapping(value = "/name/student/{name}", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "')")
public List<Student> getStudentByTeacher(@PathVariable String name) {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

/**
*/
@RestController
@RequestMapping("/v1/students")
public class StudentController {

private static Logger logger = LoggerFactory.getLogger(StudentController.class);

@Autowired
StudentService studentService;

@Autowired
UserService userService;

@ApiOperation(value = "获取学生列表", notes = "")
@RequestMapping(value = "", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "')")
public PageInfo<Student> getStudentList(@RequestBody DtoPage page) {
if(page.getPageIndex() != null && page.getPageSize() != null) {
PageHelper.startPage(page.getPageIndex(), page.getPageSize());
}
List<Student> students = studentService.getStudentList();
PageInfo pageInfo = new PageInfo(students);
return pageInfo;
}

@ApiOperation(value = "根据老师信息获取学生列表", notes = "根据老师信息获取学生列表")
@ApiImplicitParam(name = "name", value = "老师名字", required = true, dataType = "String", paramType = "path")
@RequestMapping(value = "/teacher/{name}", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "')")
public PageInfo<Student> getStudentListByTeacher(@PathVariable String name,
@RequestParam(required = false) Integer pageIndex,
@RequestParam(required = false) Integer pageSize,
@RequestParam(required = false) Integer limit,
@RequestParam(required = false) Integer offset) {
if(pageIndex != null && pageSize != null) {
PageHelper.startPage(pageIndex, pageSize);
}
List<Student> students = studentService.findStudentListByTeacher(name);
PageInfo pageInfo = new PageInfo(students);
return pageInfo;
}

@ApiOperation(value = "新增学生", notes = "新增学生")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "教师id", required = true, dataType = "path"),
@ApiImplicitParam(name = "student", value = "学生实体student", required = true, dataType = "DtoStudent")
})
@RequestMapping(value = "/{id}/teacher", method = RequestMethod.POST)
//@PreAuthorize("hasAuthority('" + Role.ROLE_TEACHER + "') or hasAuthority('" + Role.ROLE_ADMIN + "')")
public ResponseEntity<?> postStudent(@PathVariable String id, @RequestBody DtoStudent dtoStudent) {


项目链接:
https://javayms.github.io?id=411222052008200vk
https://javayms.pages.dev?id=411222052008200vk