Online examination system based on SpringBoot

Author homepage: programming compass

About the author: High-quality creator in the Java field, CSDN blog expert, invited author of Nuggets, many years of architect design experience, resident lecturer of Tencent Classroom

Main content: Java project, graduation design, resume template, learning materials, interview question bank, technical mutual assistance

Favorites, likes, don't get lost, it's good to pay attention to the author

Get the source code at the end of the article

Item Number:

1. Project Introduction

With the continuous development of computer technology, our daily life and work are more and more closely related to computer technology. The development of computer technology has changed our daily life and work habits, and also changed the speed of social development, making our lives more convenient and efficient. Internet technology developed along with computer technology has brought our lives into the information age and changed our learning and working environment. For example, the exams we often face have also changed with the development of Internet technology. With the development of information technology With the development of the Internet, an online paperless examination system came into being, which not only completely changed the habit and environment of traditional paper examinations, but also improved the efficiency of examinations, ensured the effectiveness of examinations, and achieved the purpose of examinations [1]. Traditional paper-based examinations have many limitations and deficiencies, mainly including the following:

1. Traditional paper-based examinations require more human resources and time resources to set the questions, and at the same time, the difficulty and assessment value of the questions are difficult to meet the basic requirements;

2. Manual marking is used for traditional paper-based examinations. Manual marking will inevitably lead to marking errors or errors in score calculation, which will also affect the results of the test;

3. The manual marking mode of traditional paper-based examinations will also waste a lot of human resources and time resources, and cannot guarantee work efficiency and work quality;

4. Traditional paper-based examinations are poor in summarizing the examination results, and cannot comprehensively and specifically analyze the examination results. It is also difficult for teachers to obtain basic examination result analysis data information, which is the key to improving teaching quality and teaching effect factor;

5. Traditional paper-based examinations cannot achieve uniform requirements for examination time and examination discipline, which will also affect the fairness of the examination. Based on the shortcomings of traditional paper-based examinations analyzed above, a new online examination system combined with computer technology and Internet technology emerged as the times require. It not only solves the basic problems of traditional paper-based examinations through a new technology, but also provides a A new test idea and test concept corrects the disadvantages of the traditional paper test and provides a more reasonable and effective test process.

Second, the environment introduction

Locale: Java: jdk1.8

Database: Mysql: mysql5.7, redis

Application server: Tomcat: tomcat8.5.31

Development tools: IDEA or eclipse

Background development technology: springboot, mybatisplus, springmvc, shiro, jwt, etc.

The system is divided into three roles: administrator, teacher, and student

Three, system display

Background login home page

administrator list

 

role management

 

menu management

student list

 

Professional list

 

course title

Announcement management

 

List of test papers

 

New test paper

 

Mark the papers

 

Student home page

 

my test paper

Exam Records

 

Fourth, the core code display



@Service("paperService")
public class PaperServiceImpl extends ServiceImpl<PaperDao, PaperEntity> implements PaperService {

    @Resource
    private QuestionDao questionDao;

    @Autowired
    private PaperQuestionService paperQuestionService;

    @Autowired
    private QuestionTypeService questionTypeService;

    @Resource
    private PaperClazzDao paperClazzDao;

    @Autowired
    private PaperRecordService paperRecordService;
    @Autowired
    private StudentService studentService;

    @Autowired
    private BaseService baseService;


    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String isNoChecked = (String) params.get("isNoChecked");
        String title = (String) params.get("title");
        String major = (String) params.get("major");
        String subjectId = (String) params.get("subjectId");
        QueryWrapper<PaperEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("is_deleted", 0);
        if (StringUtils.hasText(isNoChecked)) {
            wrapper.ne("is_checked", isNoChecked);
        }
        if (StringUtils.hasText(title)) {
            wrapper.eq("paper_title", title);
        }
        if (StringUtils.hasText(major)) {
            wrapper.eq("major_id", major);
        }
        if (StringUtils.hasText(subjectId)) {
            wrapper.eq("subject_id", subjectId);
        }
        IPage<PaperEntity> page = this.page(
                new Query<PaperEntity>().getPage(params),
                wrapper
        );
        page.setRecords(baseService.relation(page));
        return new PageUtils(page);
    }

    @Override
    public List<PaperQuestionVO> getPageQuestionList(Integer subjectId) {
        List<PaperQuestionVO> result = new ArrayList<>();
        List<QuestionNumVO> questionNumVOList = questionDao.getQuestionNumListBySubjectId(subjectId);
        questionNumVOList.forEach(item -> {
            PaperQuestionVO tempPageQuestion = new PaperQuestionVO();
            tempPageQuestion.setQuestionTypeId(item.getQuestionTypeId());
            tempPageQuestion.setQuestionTypeName(item.getTypeName());
            if (!result.contains(tempPageQuestion)) {
                result.add(tempPageQuestion);
            }
        });
        result.forEach(pageQuestion -> {
            List<QuestionNumVO> questionNumList = new ArrayList<>();
            questionNumVOList.forEach(questionNumVO -> {
                if (pageQuestion.getQuestionTypeId().equals(questionNumVO.getQuestionTypeId())) {
                    questionNumList.add(questionNumVO);
                }
            });
            pageQuestion.setQuestionNumList(questionNumList);
        });

        return result;
    }

    @Transactional(
            rollbackFor = Exception.class
    )
    @Override
    public void savePaperInfo(PaperDTO paperDTO) {
        PaperEntity paperEntity = new PaperEntity();
        BeanUtils.copyProperties(paperDTO, paperEntity);
        paperEntity.setExamDateStart(DateUtil.parse(paperDTO.getExamDateStart(), "yyyy-MM-dd"));
        paperEntity.setExamDateEnd(DateUtil.parse(paperDTO.getExamDateEnd(), "yyyy-MM-dd"));
        baseMapper.insert(paperEntity);
        List<PaperQuestionEntity> paperQuestionEntityList =  new ArrayList<>();
        Set<Integer> questionIds = new HashSet<>();
        paperDTO.getSeleted().forEach(item -> {
            List<QuestionEntity> questionEntities = questionDao.selectList(new QueryWrapper<QuestionEntity>()
                    .eq("is_deleted", 0)
                    .eq("subject_id", paperEntity.getSubjectId())
                    .eq("question_type_id", item.getQuestionTypeId())
                    .eq("score", item.getScore()));
            Set<Integer> tempQuestionIds = new HashSet<>();
            while (tempQuestionIds.size() != item.getSelectVal()) {
                int num = (int)(Math.random()*questionEntities.size());
                tempQuestionIds.add(questionEntities.get(num).getId());
            }
            questionIds.addAll(tempQuestionIds);
        });
        questionIds.forEach(item -> {
            PaperQuestionEntity paperQuestionEntity = new PaperQuestionEntity();
            paperQuestionEntity.setPaperId(paperEntity.getId());
            paperQuestionEntity.setQuestionId(item);
            paperQuestionEntityList.add(paperQuestionEntity);
        });
        paperQuestionService.saveBatch(paperQuestionEntityList);
    }

    @Override
    public PaperInfoVO getPaperInfoByPaperId(String paperId) {
        PaperEntity paperEntity = baseMapper.selectById(paperId);
        PaperInfoVO paperInfoVO = new PaperInfoVO();
        BeanUtils.copyProperties(paperEntity, paperInfoVO);

        List<Integer> questionIds = paperQuestionService.getBaseMapper()
                .selectList(
                        new QueryWrapper<PaperQuestionEntity>().eq("paper_id", paperId)).stream().map(item -> item.getQuestionId()).collect(Collectors.toList()
                );

        List<QuestionItemInfo> questionItemInfos = new ArrayList<>();
        List<QuestionTypeEntity> questionTypeList = questionTypeService.getBaseMapper().selectList(new QueryWrapper<QuestionTypeEntity>().eq("is_deleted", 0).orderByAsc("sort"));
        questionTypeList.forEach(item -> {
            QuestionItemInfo tempQuestionItemInfo = new QuestionItemInfo();
            BeanUtils.copyProperties(item, tempQuestionItemInfo);
            tempQuestionItemInfo.setList(
                    questionDao.selectList(new QueryWrapper<QuestionEntity>().eq("is_deleted", 0).eq("question_type_id", item.getId()).in("id", questionIds))
            );
            questionItemInfos.add(tempQuestionItemInfo);
        });
        paperInfoVO.setQuestionList(questionItemInfos);
        return paperInfoVO;
    }

    @Override
    public void updateBatchAffirmByIds(List<String> ids, String updateBy) {
        List<PaperEntity> paperList = new ArrayList<>();
        ids.forEach(id -> {
            PaperEntity paperEntity = new PaperEntity();
            paperEntity.setId(id);
            paperEntity.setIsAffirm(1);
            paperEntity.setUpdateBy(updateBy);
            paperList.add(paperEntity);
        });

        this.updateBatchById(paperList);
    }

    @Override
    public void savePaperClazzRelation(String paperId, Integer clazzId) {
        PaperClazzEntity paperClazzEntity = new PaperClazzEntity();
        paperClazzEntity.setPaperId(paperId);
        paperClazzEntity.setClazzId(clazzId);
        paperClazzDao.insert(paperClazzEntity);
    }

    @Override
    public IPage<PaperEntity> getPaperByClazzId(PaperDTO paperDTO, String clazzId, String token) throws Exception {

        String account = JWTTokenUtils.geAccountByToken(token);
        StudentEntity currentStudent = studentService.getOne(new QueryWrapper<StudentEntity>().eq("is_deleted", 0).eq("stu_no", account));

        List<String> paperIds = paperClazzDao.selectList(new QueryWrapper<PaperClazzEntity>().eq("clazz_id", clazzId)).stream().map(item -> item.getPaperId()).collect(Collectors.toList());
        baseMapper.selectBatchIds(paperIds);

        QueryWrapper<PaperEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("is_deleted", 0).in("id", paperIds);

        if (StringUtils.hasText(paperDTO.getPaperTitle())) {
            wrapper.like("paper_title", paperDTO.getPaperTitle());
        }
        if (Objects.nonNull(paperDTO.getMajorId())) {
            wrapper.eq("major_id", paperDTO.getMajorId());
        }
        if (Objects.nonNull(paperDTO.getSubjectId())) {
            wrapper.eq("subject_id", paperDTO.getSubjectId());
        }
        wrapper.eq("major_id", currentStudent.getMajor());
        IPage<PaperEntity> resultPage = this.page(
                new Page<>(paperDTO.getPageNo(), paperDTO.getPageSize()),
                wrapper
        );

        List<PaperRecordEntity> paperRecordEntities = paperRecordService.list(new QueryWrapper<PaperRecordEntity>().eq("stu_no", currentStudent.getStuNo()));
        List<PaperEntity> records = resultPage.getRecords();
        records.forEach(item -> {
            paperRecordEntities.forEach(temp -> {
                if (item.getId().equals(temp.getPaperId())) {
                    item.setAnswerNum(item.getAnswerNum() - 1);
                }
            });
        });
        resultPage.setRecords(records);
        resultPage.setRecords(baseService.relation(resultPage));
        return resultPage;
    }

    @Override
    public PaperEntity getPaperByClazzIdAndPaperId(String paperId) {
        PaperEntity paperEntity = baseMapper.selectById(paperId);
        List<PaperRecordEntity> paperRecordEntities = paperRecordService.list(new QueryWrapper<PaperRecordEntity>().eq("paper_id", paperId));
        paperEntity.setAnswerNum(paperEntity.getAnswerNum() - paperRecordEntities.size());
        return paperEntity;
    }
}



@Service("questionService")
public class QuestionServiceImpl extends ServiceImpl<QuestionDao, QuestionEntity> implements QuestionService {

    @Autowired
    private BaseService baseService;

    @Autowired
    private QuestionTypeService questionTypeService;


    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String key = (String) params.get("key");
        String typeId = (String) params.get("typeId");
        String subjectId = (String) params.get("subjectId");

        QueryWrapper<QuestionEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("is_deleted", 0);
        wrapper.orderByDesc("create_time");
        if (StringUtils.hasText(key)) {
            wrapper.like("question_title", key);
        }
        if (StringUtils.hasText(typeId)) {
            wrapper.eq("question_type_id", typeId);
        }
        if (StringUtils.hasText(subjectId)) {
            wrapper.eq("subject_id", subjectId);
        }

        IPage<QuestionEntity> page = this.page(
                new Query<QuestionEntity>().getPage(params),
                wrapper
        );
        page.setRecords(baseService.relation(page));
        return new PageUtils(page);
    }

    @Override
    public List<QuestionNumVO> getQuestionNumWithSubjectIdGroupByType(Integer subjectId) {
        return baseMapper.getQuestionNumWithSubjectIdGroupByType(subjectId);
    }

    @Override
    public List<QuestionRecordVO> getPracticeQuestionList(PaperDTO paperDTO) {

        List<QuestionRecordVO> resultLis = new ArrayList<>();

        Integer subjectId = paperDTO.getSubjectId();
        List<QuestionSelectedDTO> seleted = paperDTO.getSeleted();
        seleted.forEach(item -> {
            QuestionRecordVO questionRecordVO = new QuestionRecordVO();
            questionRecordVO.setTypeName(item.getTypeName());
            questionRecordVO.setTypeId(item.getQuestionTypeId());
            List<QuestionRecordList> record = new ArrayList<>();
            Set<Integer> questionIds = new HashSet<>();
            List<QuestionEntity> questionEntities = baseMapper.selectList(new QueryWrapper<QuestionEntity>()
                    .eq("is_deleted", 0)
                    .eq("subject_id", subjectId)
                    .eq("question_type_id", item.getQuestionTypeId()));
            while (questionIds.size() != item.getSelectVal()) {
                int num = (int)(Math.random()*questionEntities.size());
                questionIds.add(questionEntities.get(num).getId());
            }
            questionEntities.forEach(ques -> {
                if (questionIds.contains(ques.getId())) {
                    QuestionRecordList temp = new QuestionRecordList();
                    BeanUtils.copyProperties(ques, temp);
                    record.add(temp);
                }
            });
            questionRecordVO.setRecord(record);
            resultLis.add(questionRecordVO);
        });
        System.out.println("resultLis: "+resultLis.toString());
        return resultLis;
    }

}

V. Project Summary

Due to the limited space, there are still some functions not shown. This project is a very good project with beautiful interface and complete functions. Very suitable for use as a final project

Tags: Java Spring Spring Boot intellij-idea programming language

Posted by sticks464 on Sat, 25 Feb 2023 04:52:47 +0530