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

私信源码获取及调试交流

私信源码获取及调试交流

运行环境

Java≥8、MySQL≥5.7

开发工具

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

适用

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

功能说明

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

考试流程:

用户前台注册成为学生

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

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

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

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

考试查看成绩

练习流程:

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

考生查看成绩,查看错题

        }

        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")

    }

    @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) {


    @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);


        //传入的是答卷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 = "/{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);

    }

}

/**

/**

 */

@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();


    }

}

/**

 */

@RestController

@RequestMapping(value = "/v1/subjects")

public class SubjectController {

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

            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;//保存当前存在的记录

                    }

                }

                //记录不存在


            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;//保存当前存在的记录
        }

        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 + "')")

    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,

        return new ResponseEntity(HttpStatus.OK);

    }

    @ApiOperation(value = "删除题目", notes = "根据题目id删除试卷")

    })

    @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) {


    })

    @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);

    }

}


    @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) {


                    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());

    @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);

    @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")

        return new ResponseEntity(HttpStatus.OK);

    }

    @ApiOperation(value = "删除题目", notes = "根据题目id删除试卷")

    })

    @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)

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

Logo

码道开发者社区,聚焦华为云码道 CodeArts 代码智能体,沉淀 Agent、Skill、鸿蒙开发实战内容,供开发者查阅资料、交流技术、分享工程实践

更多推荐