Java implements online examination system (administrator function)

In this examination system, the three roles of administrator, teacher and student are equivalent to three systems.
Online exam system administrator login page
write picture description here
subject management page (you can add, delete, modify and check subjects)
write picture description here

/**
	 * 分页查询科目,展示给页面
	 * @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";
	}
	
	/**
	 * 跳转到添加科目页面
	 * @return
	 */
	@RequestMapping(value = "/add", method=RequestMethod.GET)
	public String addSubjectView(){
		
		return "/subject/add";
	}
	
	/**
	 * 添加科目
	 * @param subject
	 * @return
	 */
	@RequestMapping(value = "/add", method=RequestMethod.POST)
	public @ResponseBody AjaxResult addSubject(Subject subject){
		
		//判断学科名称是否为空
		if (CommonUtils.isEmpty(subject.getName())){
			return AjaxResult.errorInstance("学科名称不能为空");
		}
		//判断学科名称是否存在
		if (subjectService.isExisted(subject)){
			return AjaxResult.errorInstance("学科名称不能重复");
		}
		//添加科目
		subjectService.insert(subject);
		return AjaxResult.successInstance("添加成功");
	}
	
	/*
	 * 跳转到修改页面 
	 */
	@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";
	}
	
	/**
	 * 修改科目
	 * @param subject
	 * @return
	 */
	@RequestMapping(value = "/update",  method=RequestMethod.POST)
	public @ResponseBody AjaxResult updateSubject(Subject subject){
		
		//判断学科名称是否为空
		if (CommonUtils.isEmpty(subject.getName())){
			return AjaxResult.errorInstance("学科名称不能为空");
		}
		//判断学科名称是否存在
		if (subjectService.isExisted(subject)){
			return AjaxResult.errorInstance("学科名称不能重复");
		}
		
		subjectService.update(subject);
		return AjaxResult.successInstance("修改成功");
	}
	
	@RequestMapping(value = "/delete")
	public @ResponseBody AjaxResult deleteSubject(int id){
		
		if (!chapterService.isEmpty(id)){
			return AjaxResult.errorInstance("对不起,该课程中的篇章没有删除完,不能删除!");
		}
		subjectService.delete(id);
		return AjaxResult.successInstance("删除成功");
	}

Chapter management (multiple chapters for a subject)
write picture description here

**Student Information Management Page**
write picture description here

**Teacher information management page**
write picture description here

Teacher subject management page (subjects taught by the teacher)
write picture description here

**Class Management Page**
write picture description here

Class student management (each class has students)
write picture description here

Class subject management (each class has subjects to learn and corresponding teachers)
write picture description here

**Exam Management Page**
write picture description here

Publish the test page (according to the test subject, the type of test question module, and the number of test questions, the test paper is randomly grouped in the system, and the test question score is the score of each sub-question)
write picture description here

//发布考试时试题模块,试题数量,分值对应的JavaBean对象
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;
	}	
}
//模块集合类
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;
	}
	
}
/**
	 * 初始化时间类型
	 * @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));
	}
	
	/**
	 * 显示考试信息列表
	 * @param curr
	 * @param model
	 * @return
	 */
	@RequestMapping("/list")
	public String showExam(Integer curr, Model model){
		if (curr == null){
			curr = 1;
		}
		//查询出发布的开始信息列表
		PageInfo<Publishexam> publishexamList = publishExamService.selectAll(curr, 5);
		model.addAttribute("publishexamList", publishexamList);
		return "/exam/list";
	}
	
	/**
	 * 跳转到考试页面
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/add", method=RequestMethod.GET)
	public String addExamView(Model model){
		
		//查询试题和试题模块列表,在前端页面上显示
		List<Subject> textList = subjectService.showList();
		List<Textmodel> textModelList = textModelService.showList();
		model.addAttribute("textList", textList);
		model.addAttribute("textModelList", textModelList);
		return "/exam/add";
	}
	
	/**
	 * 添加考试信息
	 * @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){
		
		//添加考试信息,获取到是哪个管理员添加的考试信息
		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());
		//因为试题模块数量,题目数量,题目分值是一直变化的
		//存储在数据库中比较字段不好建立,因此我们将这块提取出一个TextModel类
		//将多个模块添加到List集合中转成JSON格式存储到数据库中
		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("添加成功");
	}
	
	/**
	 * 跳转到发布考试页面
	 * @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);
		//将存储的JSON取出并解析成Java对象
		ArrayList<TextModel> updateList = JsonUtils.toBean(publishExam.getExam(), ArrayList.class, TextModel.class);
		//获取科目列表
		List<Subject> textList = subjectService.showList();
		//获取试题模块列表
		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";
	}
	
	/**
	 * 修改所发布的考试
	 * @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("修改成功");
	}
	
	/**
	 * 删除考试信息
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/delete")
	public @ResponseBody AjaxResult deleteExam(int id){
		publishExamService.delete(id);
		return AjaxResult.successInstance("删除成功");
	}

**Post exam revision page**
write picture description here

** Check student grades **
write picture description here

Teacher management (can delete teacher information, reset teacher password)
write picture description here
** Student management (can delete student information, reset student password) **
write picture description here

Because it is basically a method of adding, deleting, modifying and checking, almost, it is not necessary to paste all the code. ( Posting exams and modifying exam info is a pain in the admin, so I've glued in the code )

TextModel is the JavaBean class extracted to store JSON when the test questions are published.
Textmodel is the test question module class
(the name was not paid attention to when the class was created at that time)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324222930&siteId=291194637