基于javaweb+mysql的springboot微服务springcloud在线考试系统(java+springboot+springcloud+mysql+maven)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot微服务SpringCloud在线考试系统(java+springboot+springcloud+mysql+maven)
考试流程:
用户前台注册成为学生
管理员后台添加老师,系统将该用户角色上升为老师
老师登录,添加考试,添加题目,发布考试
考生登录前台参加考试,交卷
老师后台批改试卷,查看成绩
考试查看成绩
练习流程:
考生登录前台参加练习,练习完自动判分,记录错题
考生查看成绩,查看错题
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) {
@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);
}
}
/**
*/
})
@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);
}
}
}
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);
@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删除试卷")
@RequestMapping(value = "/v1/subjects")
public class SubjectController {
private static Logger logger = LoggerFactory.getLogger(SubjectController.class);
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.已经注册
//保存
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();
//初始化信息
}
@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);
}
}
/**
*/
@RestController
@RequestMapping(value = "/v1/subjects")
public class SubjectController {
private static Logger logger = LoggerFactory.getLogger(SubjectController.class);
//保存
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();
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 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());
public List<Student> getStudentByTeacher(@PathVariable String name) {
/**
*/
@RestController
@RequestMapping("/v1/students")
public class StudentController {
private static Logger logger = LoggerFactory.getLogger(StudentController.class);
@Autowired
StudentService studentService;
@Autowired
UserService userService;
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(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());
@PathVariable Integer number,
@RequestParam(required = false) String answerPaperId) {
PaperAnswerPaper paperAnswerPaper = null;
//传入的是答卷Id
if(answerPaperId != null) {
paperAnswerPaper = paperAnswerPaperService.getByAnswerPaperId(answerPaperId);
@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)
@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 = "根据教师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) {
answerQuestion = new AnswerQuestion();
//初始化信息
answerQuestion.setId(answerQuestionId);
answerQuestion.setTitle(question.getTitle());
answerQuestion.setType(question.getType());
answerQuestion.setNumber(question.getNumber());
answerQuestion.setOptionA(question.getOptionA());
@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获取答卷失败");