Java implementation of online examination system (administrator function)

In this test system, administrator, teacher, three students role is equivalent to three systems.
Online examination system administrator login page of
Write pictures described here
discipline management page (can be subject CRUD)
Write pictures described 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 (a subject several chapters)
Write pictures described here

** ** Student Information Management page
Write pictures described here

** ** teacher information management page
Write pictures described here

Account Management page teacher (teacher taught subjects)
Write pictures described here

** ** class management page
Write pictures described here

Management students in the class (each class has a student)
Write pictures described here

Class subjects management (each class has to learn the subjects, and the corresponding teacher)
Write pictures described here

** Exam Management page **
Write pictures described here

Posted test page (based on test subjects, test the module type, the number of questions randomly test paper in the system, test scores for the score for each small question)
Write pictures described 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("删除成功");
	}

** modified release test page **
Write pictures described here

** ** student achievement query
Write pictures described here

Teacher management (you can delete teacher information, password reset teacher)
Write pictures described here
** Student Administration (can delete student information, reset student passwords) **
Write pictures described here

Because basically CRUD method, almost all the code paste is not necessary. ( Posted exam and modify exam information is the difficulty Administrator, so I stick out of the Code )

TextModel is released JavaBean class questions in order to store JSON extracted
Textmodel are questions module class
(the class was created when no attention name)

Published 39 original articles · won 157 Like · views 90000 +

Guess you like

Origin blog.csdn.net/qq_34417749/article/details/80850986