Java realizes online examination system (administrator function)

Keywords: JSON Session Database Java

In this examination system, the three roles of administrator, teacher and student are equivalent to three systems.
Online examination system administrator login page

Subject management page (subject can be added, deleted, modified and checked)

/**
	 * Query accounts in pages and show them to the page
	 * @param curr
	 * @param model
	 * @return
	 */
	@RequestMapping("/list")
	public String showSubject(Integer curr, Model model){
		
		if (curr == null){
			curr = 1;
		}
		
		PageInfo<Subject> pageInfo = subjectService.showList(curr, 5);
		model.addAttribute("pageInfo", pageInfo);
		
		return "/subject/list";
	}
	
	/**
	 * Jump to add account page
	 * @return
	 */
	@RequestMapping(value = "/add", method=RequestMethod.GET)
	public String addSubjectView(){
		
		return "/subject/add";
	}
	
	/**
	 * Add subject
	 * @param subject
	 * @return
	 */
	@RequestMapping(value = "/add", method=RequestMethod.POST)
	public @ResponseBody AjaxResult addSubject(Subject subject){
		
		//Judge whether the subject name is empty
		if (CommonUtils.isEmpty(subject.getName())){
			return AjaxResult.errorInstance("Subject name cannot be empty");
		}
		//Judge whether the subject name exists
		if (subjectService.isExisted(subject)){
			return AjaxResult.errorInstance("Subject name cannot be duplicate");
		}
		//Add subject
		subjectService.insert(subject);
		return AjaxResult.successInstance("Add success");
	}
	
	/*
	 * Jump to modify page 
	 */
	@RequestMapping(value = "/update",  method=RequestMethod.GET)
	public String updateSubjectView(int id, Model model){
		
		Subject subject = subjectService.selectOne(id);
		model.addAttribute("subject", subject);
		return "/subject/update";
	}
	
	/**
	 * Revised subjects
	 * @param subject
	 * @return
	 */
	@RequestMapping(value = "/update",  method=RequestMethod.POST)
	public @ResponseBody AjaxResult updateSubject(Subject subject){
		
		//Judge whether the subject name is empty
		if (CommonUtils.isEmpty(subject.getName())){
			return AjaxResult.errorInstance("Subject name cannot be empty");
		}
		//Judge whether the subject name exists
		if (subjectService.isExisted(subject)){
			return AjaxResult.errorInstance("Subject name cannot be duplicate");
		}
		
		subjectService.update(subject);
		return AjaxResult.successInstance("Modified success");
	}
	
	@RequestMapping(value = "/delete")
	public @ResponseBody AjaxResult deleteSubject(int id){
		
		if (!chapterService.isEmpty(id)){
			return AjaxResult.errorInstance("I'm sorry,The chapters in this course have not been deleted,Cannot delete!");
		}
		subjectService.delete(id);
		return AjaxResult.successInstance("Delete successful");
	}

Chapter Management (a subject has multiple chapters)

**Student information management page**

**Teacher information management page**

Teacher subject management page (subjects taught by teachers)

**Class management page**

Class student management (each class has students)

Class subject management (each class has subjects to learn and corresponding teachers)

**Test management page**

Release the test page (randomly group papers in the system according to the test subjects, test module types and test quantity, and the test score is the score of each small question)

//Release the JavaBean object corresponding to the test module, number of test questions and scores
public class TextModel {
	
	private Integer textModelId;
	private Integer textCount;
	private Integer grade;
	public Integer getTextModelId() {
		return textModelId;
	}
	public void setTextModelId(Integer textModelId) {
		this.textModelId = textModelId;
	}
	public Integer getTextCount() {
		return textCount;
	}
	public void setTextCount(Integer textCount) {
		this.textCount = textCount;
	}
	public Integer getGrade() {
		return grade;
	}
	public void setGrade(Integer grade) {
		this.grade = grade;
	}	
}
//Module collection class
public class BeanTextModel {

	private List<TextModel> listTextModel = new ArrayList<TextModel>();

	public List<TextModel> getListTextModel() {
		return listTextModel;
	}

	public void setListTextModel(List<TextModel> listTextModel) {
		this.listTextModel = listTextModel;
	}
	
}
/**
	 * Initialization time type
	 * @param binder
	 */
	@InitBinder
	public void initBinder(WebDataBinder binder) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
	}
	
	/**
	 * Show exam information list
	 * @param curr
	 * @param model
	 * @return
	 */
	@RequestMapping("/list")
	public String showExam(Integer curr, Model model){
		if (curr == null){
			curr = 1;
		}
		//Query out the list of published start information
		PageInfo<Publishexam> publishexamList = publishExamService.selectAll(curr, 5);
		model.addAttribute("publishexamList", publishexamList);
		return "/exam/list";
	}
	
	/**
	 * Jump to exam page
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/add", method=RequestMethod.GET)
	public String addExamView(Model model){
		
		//Query the list of test questions and test modules, and display them on the front page
		List<Subject> textList = subjectService.showList();
		List<Textmodel> textModelList = textModelService.showList();
		model.addAttribute("textList", textList);
		model.addAttribute("textModelList", textModelList);
		return "/exam/add";
	}
	
	/**
	 * Add exam information
	 * @param request
	 * @param publishExam
	 * @param textModelIds
	 * @param beanTextModel
	 * @return
	 */
	@RequestMapping(value="/add", method=RequestMethod.POST)
	@ResponseBody
	public AjaxResult addExam(HttpServletRequest request,PublishexamWithBLOBs publishExam,int[] textModelIds, BeanTextModel beanTextModel){
		
		//Add test information to get the test information added by which administrator
		HttpSession session = request.getSession();
		Admin admin = (Admin) session.getAttribute("adminInfo");
		publishExam.setAdminId(admin.getId()); 
		publishExam.setAdminName(admin.getName());
		publishExam.setStatus(0);
		publishExam.setPublishtime(new Date());
		//Find out the subjects of the test
		Subject subject = subjectService.selectOne(publishExam.getSubjectId());
		publishExam.setSubjectName(subject.getName());
		//Because the number of modules, the number of questions and the score of questions are always changing
		//The comparison field stored in the database is not easy to establish, so we extract a TextModel class from this part
		//Add multiple modules to the List collection, transfer them to JSON format and store them in the database
		List<TextModel> list = new ArrayList<TextModel>();
		if (textModelIds != null){
			for (int i : textModelIds) {
				for(TextModel textModel : beanTextModel.getListTextModel()){
					if (textModel.getTextModelId() != null && i == textModel.getTextModelId()){
						list.add(textModel);
					}
				}
			}
			String json = JsonUtils.toJson(list);
			publishExam.setExam(json);
		}
		publishExamService.insert(publishExam);
		
		return AjaxResult.successInstance("Add success");
	}
	
	/**
	 * Jump to the release exam page
	 * @param id
	 * @param model
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value="/update", method=RequestMethod.GET)
	public String updateExamView(int id, Model model){
		PublishexamWithBLOBs publishExam = publishExamService.selectByKey(id);
		//Take out the stored JSON and parse it into Java objects
		ArrayList<TextModel> updateList = JsonUtils.toBean(publishExam.getExam(), ArrayList.class, TextModel.class);
		//Get account list
		List<Subject> textList = subjectService.showList();
		//Get the list of test modules
		List<Textmodel> textModelList = textModelService.showList();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String date = dateFormat.format(publishExam.getExamtime());
		model.addAttribute("date", date);
		model.addAttribute("textList", textList);
		model.addAttribute("textModelList", textModelList);
		model.addAttribute("updateList", updateList);
		model.addAttribute("publishExam", publishExam);
		return "/exam/update";
	}
	
	/**
	 * Revise the published exam
	 * @param request
	 * @param id
	 * @param publishExam
	 * @param textModelIds
	 * @param beanTextModel
	 * @return
	 */
	@RequestMapping(value="/update", method=RequestMethod.POST)
	@ResponseBody
	public AjaxResult updateExam(HttpServletRequest request,int id, PublishexamWithBLOBs publishExam,int[] textModelIds, BeanTextModel beanTextModel){
		HttpSession session = request.getSession();
		Admin admin = (Admin) session.getAttribute("adminInfo");
		publishExam.setAdminId(admin.getId()); 
		publishExam.setAdminName(admin.getName());
		publishExam.setStatus(0);
		publishExam.setPublishtime(new Date());
		Subject subject = subjectService.selectOne(publishExam.getSubjectId());
		publishExam.setSubjectName(subject.getName());
		List<TextModel> list = new ArrayList<TextModel>();
		if (textModelIds != null){
			for (int i : textModelIds) {
				for(TextModel textModel : beanTextModel.getListTextModel()){
					if (textModel.getTextModelId() != null && i == textModel.getTextModelId()){
						list.add(textModel);
					}
				}
			}
			String json = JsonUtils.toJson(list);
			publishExam.setExam(json);
		}
		publishExamService.update(publishExam);
		return AjaxResult.successInstance("Modified success");
	}
	
	/**
	 * Delete exam information
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/delete")
	public @ResponseBody AjaxResult deleteExam(int id){
		publishExamService.delete(id);
		return AjaxResult.successInstance("Delete successful");
	}

**Publish exam modification page**

**Query student scores**

Teacher management (can delete teacher information and reset teacher password)

**Student management (can delete student information and reset student password)**

Because it's basically a method of adding, deleting, modifying and querying, almost all of which are unnecessary to paste. (releasing and modifying exam information is a difficult task for administrators, so I stuck out the code)

TextModel is a JavaBean class extracted to store JSON when releasing test questions
Textmodel is a test module class
(the class was not named when it was created.)

39 original articles published, 157 praised, 90000 visitors+
Private letter follow

Posted by Sfoot on Fri, 14 Feb 2020 05:10:24 -0800