Java项目:作业管理系统(java+SpringBoot+BootStrap+HTML+Thymeleaf+mysql)

源码获取:博客首页 "资源" 里下载!

项目介绍

该项目分为学生、教师两个角色,主要功能如下:

1. 学生模块

1) 我的课程:学生可在此页面自由选课
2) 我的作业:可查看选择的课程已发布的作业及完成情况,并可选择完成作业或查看详情

2. 教师模块

1) 学生管理:
I. 查询学生:可根据学生信息搜索学生,可进行修改删除操作,可进行全选批量删除和导出excel表格,可根据查询到的数据进行分页,输入页码进行跳转操作
II. 添加学生:可进行单个添加学生或excel表格导入学生
2) 教师管理:
I. 查询教师:可根据教师信息搜索教师,可进行修改删除操作,可进行全选批量删除和导出excel表格,可根据查询到的数据进行分页,输入页码进行跳转操作
II. 添加教师:可进行单个添加学生或excel表格导入教师

3) 班级管理:
I. 查询班级:可查看所有班级,进行删除修改等操作
II. 添加班级:可进行添加班级操作
4) 课程管理:
I. 查询课程:可查看所有课程,进行修改删除操作
II. 添加班级:可进行添加课程操作
5) 作业管理:
I. 查看作业完成情况:可查看每门科目项目学生作业的完成情况,可根据起止时间和课程名称进行搜索。
II. 添加作业:选择一门课程搜索题库,在题库中选择题目后进行作业发布操作
III. 编辑题库:可对题库进行增删改操作

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.数据库:MySql 5.7版本;

6.是否Maven项目:是

技术栈

1. 后端:SpringBoot+Mybatis+Thymeleaf模板引擎

2. 前端:HTML+CSS+JavaScript+BootStrap

使用说明

1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.properties配置文件中的数据库配置改为自己的配置;
4. 运行项目,输入localhost:8080/ 登录
教师账号:js 密码:123456
学生账号:wangyi 密码:123456

 

 

 

 

 

 

老师管理控制层:

/**
 *
 * <p>
 * Title: TeacherInfoHandler
 * </p>
 * <p>
 * Description: 教师
 * </p>
 */

@Controller
@SuppressWarnings("all")
public class TeacherInfoHandler {

	@Autowired
	private TeacherInfoService teacherInfoService;

	private Logger logger = Logger.getLogger(TeacherInfoHandler.class);

	/**
	 * 获取 验证教师信息
	 * 
	 * @param teacherAccount
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value = "/validateTeacher", method = RequestMethod.POST)
	public void queryTeacherExists(@RequestParam(value = "account") String teacherAccount, HttpServletResponse response)
			throws Exception {
		logger.info("获取教师 " + teacherAccount + " 的信息");

		TeacherInfo teacherInfo = null;
		teacherInfo = teacherInfoService.getTeacherByAccount(teacherAccount);

		// 教师账户不存在
		if (teacherInfo == null) {
			response.getWriter().print("1");
		} else {
			response.getWriter().print(teacherInfo.getTeacherPwd());
		}
	}

	/**
	 * 教师登录
	 * 
	 * @param teacherAccount
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/teacherlogin", method = RequestMethod.POST)
	public String teacherLogin(@RequestParam("teacherAccount") String teacherAccount, HttpServletRequest request) {
		if (teacherAccount == null || "".equals(teacherAccount)) {
			logger.error("教师账号为空");
			request.setAttribute("error", "登录信息有误");
			return "/error";
		}
		logger.info("教师  " + teacherAccount + " 登录");

		// 获取当前登录教师
		TeacherInfo teacherInfo = teacherInfoService.getTeacherByAccount(teacherAccount);

		if (teacherInfo == null) {
			logger.error("教师账号为空");
			request.setAttribute("error", "账号不存在!");
			return "/error";
		}
		String teacherPwd = request.getParameter("teacherPwd");
		if (!teacherInfo.getTeacherPwd().equals(teacherPwd)) {
			logger.error("密码错误");
			request.setAttribute("error", "密码错误!");
			return "/error";
		}
		// 将当前登录教师 后台权限存入 Session
		request.getSession().setAttribute("adminPower", teacherInfo.getAdminPower());
		request.getSession().setAttribute("loginTeacher", teacherInfo);

		return "redirect:admin/index.jsp";
	}

	/**
	 * 教师查看自己的信息
	 * 
	 * @param teacherId
	 * @return
	 */
	@RequestMapping("/selfinfo/{teacherId}")
	public ModelAndView loginTeacherSelf(@PathVariable("teacherId") Integer teacherId) {
		ModelAndView model = new ModelAndView();
		logger.error("教师 " + teacherId + " 查看自己的信息");
		if (teacherId == null) {
			model.setViewName("../error");
			return model;
		} else {
			List<TeacherInfo> teachers = new ArrayList<TeacherInfo>();
			TeacherInfo teacher = teacherInfoService.getTeacherById(teacherId);
			teachers.add(teacher);
			model.addObject("teachers", teachers);
			model.setViewName("/admin/teacher/teachers");

			return model;
		}
	}

	/**
	 * 教师退出登录
	 * 
	 * @throws IOException
	 */
	@RequestMapping("/exitTeacher")
	public void exitTeacher(HttpSession session, HttpServletResponse response) throws IOException {
		session.removeAttribute("loginTeacher");
		session.removeAttribute("adminPower");

		response.sendRedirect("admin/login.jsp");
	}

	/**
	 * 查询教师集合
	 * 
	 * @param startPage
	 * @param pageShow
	 * @return
	 */
	@RequestMapping(value = "/teachers", method = RequestMethod.GET)
	public ModelAndView getTeachers(
			@RequestParam(value = "startPage", required = false, defaultValue = "1") Integer startPage, // 当前页码,默认第一页
			@RequestParam(value = "pageShow", required = false, defaultValue = "10") Integer pageShow /*
																										 * 每页显示数据量
																										 * ,
																										 * 默认10条
																										 */) {
		logger.info("查询教师集合");

		ModelAndView model = new ModelAndView();
		model.setViewName("admin/teacher/teachers");

		List<TeacherInfo> teachers;

		Map<String, Object> map = new HashMap<String, Object>();
		// 计算当前查询起始数据索引
		int startIndex = (startPage - 1) * pageShow;
		map.put("startIndex", startIndex);
		map.put("pageShow", pageShow);
		map.put("teacher", null);
		teachers = teacherInfoService.getTeachers(map);
		model.addObject("teachers", teachers);

		// 获取教师总量
		int teacherTotal = teacherInfoService.getTeacherTotal();
		// 计算总页数
		int pageTotal = 1;
		if (teacherTotal % pageShow == 0)
			pageTotal = teacherTotal / pageShow;
		else
			pageTotal = teacherTotal / pageShow + 1;
		model.addObject("pageTotal", pageTotal);
		model.addObject("pageNow", startPage);

		return model;
	}

	/**
	 * 预修改教师
	 * 
	 * @param teacherId
	 * @return
	 */
	@RequestMapping(value = "/teacher/{teacherId}", method = RequestMethod.GET)
	public ModelAndView preUpdateTeacher(@PathVariable("teacherId") Integer teacherId) {
		logger.info("预修改教师处理");

		ModelAndView model = new ModelAndView();
		// 获取要修改教师
		TeacherInfo teacher = teacherInfoService.getTeacherById(teacherId);
		model.setViewName("/admin/teacher/teacheredit");
		model.addObject("teacher", teacher);

		return model;
	}

	/**
	 * 修改/添加 教师
	 * 
	 * @param teacherId
	 * @param isUpdate
	 *            操作标识
	 * @param teacherName
	 * @param teacherAccount
	 * @param teacherPwd
	 * @param adminPower
	 * @return
	 */
	@RequestMapping(value = "/teacher/teacher", method = RequestMethod.POST)
	public String isUpdateOrAddTeacher(@RequestParam(value = "teacherId", required = false) Integer teacherId,
			@RequestParam(value = "isupdate", required = false) Integer isUpdate,
			@RequestParam("teacherName") String teacherName, @RequestParam("teacherAccount") String teacherAccount,
			@RequestParam("teacherPwd") String teacherPwd, @RequestParam("adminPower") Integer adminPower) {

		TeacherInfo teacher = new TeacherInfo();
		teacher.setTeacherId(teacherId);
		teacher.setTeacherName(teacherName);
		teacher.setTeacherAccount(teacherAccount);
		teacher.setTeacherPwd(teacherPwd);
		teacher.setAdminPower(adminPower);

		if (isUpdate != null) { // 修改
			logger.info("修改教师 " + teacher + " 的信息");
			int row = teacherInfoService.isUpdateTeacherInfo(teacher);
		} else { // 添加
			logger.info("添加教师 " + teacher + " 的信息");
			int row = teacherInfoService.isAddTeacherInfo(teacher);
		}

		return "redirect:/teachers";
	}

	/**
	 * 删除教师
	 * 
	 * @param teacherId
	 * @return
	 */
	@RequestMapping(value = "/teacher/{teacherId}", method = RequestMethod.DELETE)
	public String isDelTeacher(@PathVariable("teacherId") Integer teacherId) {
		logger.info("删除教师 " + teacherId);

		int row = teacherInfoService.isDelTeacherInfo(teacherId);

		return "redirect:/teachers";
	}
}

学生管理控制层:

@Controller
@SuppressWarnings("all")
public class StudentInfoHandler {

	@Autowired
	private StudentInfoService studentInfoService;
	@Autowired
	private ClassInfoService classInfoService;
	@Autowired
	private ExamSubjectMiddleInfoService examSubjectMiddleInfoService;
	@Autowired
	private ExamHistoryPaperService examHistoryPaperService;
	@Autowired
	private ExamChooseInfoService examChooseInfoService;
	@Autowired
	private ExamSubjectMiddleInfo esm;
	@Autowired
	private ClassInfo classInfo;
	@Autowired
	private ExamPaperInfo examPaper;
	@Autowired
	private GradeInfo grade;
	@Autowired
	private StudentInfo student;
	
	@Autowired
	private ExamPaperInfoService examPaperInfoService;

	private Logger logger = Logger.getLogger(StudentInfoHandler.class);

	/**
	 * 获取学生集合
	 * @param studentId 学生编号
	 * @param classId 班级编号
	 * @param gradeId 系部编号
	 * @param startPage 起始页 default=1
	 * @param pageShow 页容量 default=10
	 * @return
	 */
	@RequestMapping("/students")
	public ModelAndView getCourses(@RequestParam(value = "studentId", required = false) Integer studentId,
			@RequestParam(value = "classId", required = false) Integer classId,
			@RequestParam(value = "gradeId", required = false) Integer gradeId,
			@RequestParam(value="startPage", required=false, defaultValue="1") Integer startPage,
			@RequestParam(value="pageShow", required=false, defaultValue="10") Integer pageShow ) {
		logger.info("获取学生集合  classId="+classId+", gradeId="+gradeId+", startPage="+startPage+", pageShow="+pageShow);
		ModelAndView model = new ModelAndView();
		model.setViewName("/admin/student/students");

		//查询条件处理
		StudentInfo student = new StudentInfo();
		if (studentId != null)
			student.setStudentId(studentId);
		if (classId != null) {
			classInfo.setClassId(classId);
			student.setClassInfo(classInfo);
		}
		if (gradeId != null) {
			grade.setGradeId(gradeId);
			student.setGrade(grade);
		}
		
		Map<String, Object> map = new HashMap<String, Object>();
		//计算当前查询起始数据索引
		int startIndex = (startPage-1) * pageShow;
		map.put("student", student);
		map.put("startIndex", startIndex);
		map.put("pageShow", pageShow);
		List<StudentInfo> students = studentInfoService.getStudents(map);
		model.addObject("students", students);
		
		//获取学生总量
		int studentTotal = studentInfoService.getStudentTotal();
		//计算总页数
		int pageTotal = 1;
		if (studentTotal % pageShow == 0)
			pageTotal = studentTotal / pageShow;
		else
			pageTotal = studentTotal / pageShow + 1;			
		model.addObject("pageTotal", pageTotal);
		model.addObject("pageNow", startPage);

		return model;
	}

	/**
	 * 根据编号获取学生信息
	 * @param studentId
	 * @return
	 */
	@RequestMapping("/student/{studentId}")
	public ModelAndView getCourseById(@PathVariable("studentId") Integer studentId) {
		logger.info("获取学生 " + studentId);
		ModelAndView model = new ModelAndView();
		model.setViewName("/admin/student/studentedit");

		StudentInfo student = studentInfoService.getStudentById(studentId);
		model.addObject("student", student);
		List<ClassInfo> classes = classInfoService.getClasses(null);
		model.addObject("classes", classes);

		return model;
	}

	/**
	 * 添加/修改学生信息
	 * @param studentId
	 * @param isUpdate 操作标识
	 * @param studentName
	 * @param studentAccount
	 * @param studentPwd
	 * @param classId
	 * @return
	 */
	@RequestMapping(value = "/student/student", method = RequestMethod.POST)
	public String isUpdateOrAddCourse(
			@RequestParam(value = "studentId", required = false) Integer studentId,
			@RequestParam(value = "isupdate", required = false) Integer isUpdate,
			@RequestParam(value = "studentName", required = false) String studentName,
			@RequestParam("studentAccount") String studentAccount,
			@RequestParam("studentPwd") String studentPwd,
			@RequestParam("classId") Integer classId) {

		StudentInfo student = new StudentInfo();
			student.setStudentId(studentId);
			student.setStudentName(studentName);
			student.setStudentAccount(studentAccount);
			student.setStudentPwd(studentPwd);
			classInfo.setClassId(classId);
			student.setClassInfo(classInfo);

		if (isUpdate != null) {
			logger.info("修改学生 " + student + " 的信息");
			int row = studentInfoService.isUpdateStudent(student);
		} else {
			logger.info("添加学生 " + student + " 的信息");
			int row = studentInfoService.isAddStudent(student);
		}

		return "redirect:/students";
	}

	/**
	 * 删除学生
	 * @param studentId
	 * @return
	 */
	@RequestMapping(value = "/student/{studentId}", method = RequestMethod.DELETE)
	public String isDelTeacher(@PathVariable("studentId") Integer studentId) {
		logger.info("删除学生 " + studentId);

		int row = studentInfoService.isDelStudent(studentId);

		return "redirect:/students";
	}

	/**
	 * 预添加学生
	 * @return
	 */
	@RequestMapping("/preAddStudent")
	public ModelAndView preAddStudent() {
		logger.info("预添加学生信息");
		ModelAndView model = new ModelAndView();
		model.setViewName("/admin/student/studentedit");
		List<ClassInfo> classes = classInfoService.getClasses(null);
		model.addObject("classes", classes);

		return model;
	}
	
	/**
	 * 学生考试登录验证
	 * 
	 * 此处验证并不合理 登录验证实现如下:
	 *   前台学生登录传入账户,后台根据账户获取学生密码
	 *   返回学生密码,前台登录焦点离开密码框使用 JavaScript 判断
	 * 
	 * @param studentAccount 学生登录账户
	 * @param response
	 * @throws IOException
	 */
	@RequestMapping("/validateLoginStudent")
	public void validateLoginStudent(@RequestParam("studentAccount") String studentAccount,
			HttpServletResponse response) throws IOException {
		logger.info("学生账户 "+studentAccount+",尝试登录考试");
		
		//获取需要登录的学生对象
		StudentInfo student = studentInfoService.getStudentByAccountAndPwd(studentAccount);
		
		if (student == null) {
			logger.error("登录学生账户 "+studentAccount+" 不存在");
			response.getWriter().print("n");
		} else {
			logger.error("登录学生账户 "+studentAccount+" 存在");
			response.getWriter().print(student.getStudentPwd());
		}
	}
	
	/**
	 * 学生登录考试
	 * @param student 登录学生
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/studentLogin", method=RequestMethod.POST)
	public ModelAndView studentLogin(StudentInfo student, HttpServletRequest request) {
		ModelAndView model = new ModelAndView();
		StudentInfo loginStudent = studentInfoService.getStudentByAccountAndPwd(student.getStudentAccount());
		logger.info("学生 "+loginStudent+" 有效登录");
		if(loginStudent == null || !student.getStudentPwd().equals(loginStudent.getStudentPwd())){
			model.setViewName("reception/suc");
			model.addObject("success", "密码错误");
			return model;
		}
		request.getSession().setAttribute("loginStudent", loginStudent);
		
		model.setViewName("reception/suc");
		model.addObject("success", "登录成功");
		
		return model;
	}
	
	/**
	 * 退出登录
	 * @param session
	 * @return
	 */
	@RequestMapping("/exit")
	public String studentClearLogin(HttpSession session) {
		StudentInfo studnet = (StudentInfo) session.getAttribute("loginStudent");
		logger.info("学生 "+studnet.getStudentName()+", 编号 "+studnet.getStudentId()+" 退出登录");
		session.removeAttribute("loginStudent");
		
		return "redirect:index.jsp";
	}
	
	/**
	 * 学生注册 验证当前账户是否被占用
	 * @param studentAccount 注册账户
	 * @param response
	 * @throws IOException
	 */
	@RequestMapping("/validateAccount")
	public void validateRegisterAccount(@RequestParam("studentAccount") String studentAccount,
			HttpServletResponse response) throws IOException {
		logger.info("验证学生账户 "+studentAccount+",是否已被注册");
		
		StudentInfo student = studentInfoService.getStudentByAccountAndPwd(studentAccount);
		
		if (student == null) {
			logger.error("注册学生账户 "+studentAccount+" 可以注册");
			response.getWriter().print("t");
		} else {
			logger.error("注册学生账户 "+studentAccount+" 已被注册");
			response.getWriter().print("f");
		}
	}
	
	/**
	 * 学生注册
	 * @param studentName
	 * @param studentAccount
	 * @param studentPwd
	 * @param classId
	 * @param response
	 * @throws IOException
	 */
	@RequestMapping(value="/studentReg", method=RequestMethod.POST)
	public void studentRegister(
			@RequestParam("name") String studentName,
			@RequestParam("account") String studentAccount,
			@RequestParam("pwd") String studentPwd,
			@RequestParam("classId") Integer classId,
			HttpServletResponse response) throws IOException {
		ModelAndView model = new ModelAndView();
		student.setStudentName(studentName);
		student.setStudentAccount(studentAccount);
		student.setStudentPwd(studentPwd);
		classInfo.setClassId(classId);
		student.setClassInfo(classInfo);
		logger.info("学生注册 "+student);
		int row = studentInfoService.isAddStudent(student);
		
		response.getWriter().print("t");
	}
	
	/**
	 * 预注册
	 * @return
	 */
	@RequestMapping("/preStudentReg")
	public ModelAndView preStudentReg() {
		ModelAndView model = new ModelAndView();
		model.setViewName("reception/register");
		model.addObject("classs", classInfoService.getClasses(null));
		return model;
	}
	
	/**
	 * 学生进入考试
	 * @param classId 班级编号
	 * @param examPaperId 试卷编号
	 * @param studentId 考生编号
	 * @param examTime 考试时间
	 * @param beginTime 考试开始时间
	 * @param gradeId 系部编号
	 * @param session
	 * @return
	 */
	@RequestMapping("/begin")
	public ModelAndView beginExam(
			@RequestParam("classId") Integer classId,
			@RequestParam("examPaperId") Integer examPaperId,
			@RequestParam(value="studentId", required=false) Integer studentId,
			@RequestParam("examTime") Integer examTime,
			@RequestParam("beginTime") String beginTime,
			@RequestParam("gradeId") Integer gradeId,
			HttpSession session) {
		ModelAndView model = new ModelAndView();
		
		/*
		 * 查询该考试当前进入的试卷是否已经在历史记录中存在
		 * 如果存在,则不能再次进入考试; 反之进入考试
		 */
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("studentId", studentId);
		map.put("examPaperId", examPaperId);
		int count = examHistoryPaperService.getHistoryInfoWithIds(map);
		if(session.getAttribute("loginStudent") == null) {
			model.addObject("error", "请先登录后再操作");
			model.setViewName("error");
			return model;
		} else if (count >= 1) {
			model.addObject("error", "不能重复考试");
			model.setViewName("error");
			return model;
		} else {			
			logger.info("学生 "+studentId+" 进入考试 班级 "+classId+" 试卷 "+examPaperId);
			model.setViewName("/reception/exam");
			
			ExamPaperInfo examPaper = new ExamPaperInfo();
			examPaper.setExamPaperId(examPaperId);
			esm.setExamPaper(examPaper);
			//获取试卷 试题集合
			List<ExamSubjectMiddleInfo> esms = examSubjectMiddleInfoService.getExamPaperWithSubject(esm);
			logger.info("考试试题总量 "+esms.size());
			
			//获取当前考生在当前试卷中已选答案记录
			Map<String, Object> choosedMap = new HashMap<String, Object>();
			choosedMap.put("studentId", studentId);
			choosedMap.put("examPaperId", examPaperId);
			List<ExamChooseInfo> chooses = examChooseInfoService.getChooseInfoWithSumScore(choosedMap); 
			if (chooses == null || chooses.size() == 0) {
				model.addObject("chooses", null);
			} else {
				model.addObject("chooses", chooses);				
			}
			
			
			model.addObject("esms", esms);
			model.addObject("sumSubject", esms.size());
			model.addObject("examPaperId", examPaperId);
			model.addObject("examTime", examTime);
			model.addObject("beginTime", beginTime);
			model.addObject("classId", classId);
			model.addObject("gradeId", gradeId);
			
			return model;
		}
	}
	
	
	/**
	 * 获取学生历史考试记录
	 * @param studentId 学生编号
	 * @return
	 */
	@RequestMapping("/history/{studentId}")
	public ModelAndView getExamHistoryInfo(@PathVariable("studentId") Integer studentId) {
		ModelAndView model = new ModelAndView();
		
		if (studentId == null) {
			logger.error("学生编号 为空");
			model.setViewName("error");
			return model;
		}
		logger.info("学生 "+studentId+" 获取考试历史记录");
		//获取历史考试信息记录集合
		List<ExamHistoryPaper> ehps = examHistoryPaperService.getExamHistoryToStudent(studentId);
		model.addObject("ehps", ehps);
		model.setViewName("/reception/examHistory");
		
		return model;
	}
	
	
	/**
	 * 考生提交考试
	 * @param studentId
	 * @param examPaperId
	 * @param classId
	 * @param gradeId
	 * @return
	 */
	@RequestMapping(value="/submit", method={RequestMethod.POST, RequestMethod.GET})
	public String examSubmit(
			@RequestParam("studentId") Integer studentId,
			@RequestParam("examPaperId") Integer examPaperId,
			@RequestParam("classId") Integer classId,
			@RequestParam("gradeId") Integer gradeId) {
		logger.info("学生 "+studentId+" 提交了试卷 "+examPaperId);
		
		//获取当前学生当前试卷所选择的全部答案
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("studentId", studentId);
		map.put("examPaperId", examPaperId);
		List<ExamChooseInfo> chooses = examChooseInfoService.getChooseInfoWithSumScore(map);
		logger.info("学生 "+studentId+" 共选择了 "+chooses.size()+" 道题");
		
		//总分记录
		int sumScore = 0;
		for (ExamChooseInfo choose : chooses) {
			SubjectInfo subject = choose.getSubject();
			String chooseResult = choose.getChooseResult();
			String rightResult = subject.getRightResult();
			
			if (chooseResult.equals(rightResult)) {	//答案正确
				sumScore += subject.getSubjectScore();
				logger.info("学生 "+studentId+" 第 "+subject.getSubjectId()+" 选择正确答案 "+chooseResult+" 当前总分 "+sumScore);
			} else {
				logger.info("学生 "+studentId+" 第 "+subject.getSubjectId()+" 答案选择错误 "+chooseResult+" 正确答案为 "+rightResult+" 当前总分 "+sumScore);				
			}
		}
		
		/*
		 * 首先判断当前记录是否已经添加过
		 * 防止当前学生点击提交后,系统倒计时再次进行提交
		 */
		int count = examHistoryPaperService.getHistoryInfoWithIds(map);
		
		if (count == 0) {
			//添加到历史记录
			map.put("examScore", sumScore);
			int row = examHistoryPaperService.isAddExamHistory(map);
			logger.info("学生 "+studentId+" 提交的试卷 "+examPaperId+" 已成功处理,并添加到历史记录中");
		}
		
		return "redirect:willexams?gradeId="+gradeId+"&classId="+classId+"&studentId="+studentId;
	}
	
	
	/**
	 * 学生回顾试卷  --  后台教师查看也调用此方法
	 * @param studentId
	 * @param examPaperId
	 * @param score
	 * @param examPaperName
	 * @param studentName  后台教师查看需传入学生姓名
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping("/review")
	public ModelAndView reViewExam(
			@RequestParam("studentId") Integer studentId,
			@RequestParam("examPaperId") Integer examPaperId,
			@RequestParam("score") Integer score,
			@RequestParam("examPaperName") String examPaperName,
			@RequestParam(value="studentName", required=false) String studentName) throws UnsupportedEncodingException {
		ModelAndView model = new ModelAndView();
		if (studentId == null) {
			model.addObject("error", "请先登录后再操作");
			model.setViewName("error");
			return model;
		} else {
			//获取当前试卷的试题集合  -- 前台判断需要
			examPaper.setExamPaperId(examPaperId);
			esm.setExamPaper(examPaper);
			List<ExamSubjectMiddleInfo> esms = examSubjectMiddleInfoService.getExamPaperWithSubject(esm);
			
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("studentId", studentId);
			map.put("examPaperId", examPaperId);
			
			//获取当前回顾试卷 试题、选择答案 信息
			List<ExamChooseInfo> reviews = examChooseInfoService.getChooseInfoWithExamSubject(map);
			logger.info("学生 "+studentId+" 回顾试卷 "+examPaperId+" 试题数量 "+reviews.size());
			//设置试卷名称、试卷总分
			model.addObject("examPaperName", examPaperName);
			model.addObject("score", score);
			
			model.setViewName("reception/review");
			model.addObject("views", reviews);
			
			model.addObject("esms", esms);
			if (studentName != null) model.addObject("studentName", studentName);
			
			model.addObject("ExamedPaper", examPaperInfoService.getExamPaper(examPaperId));
			
			return model;
		}
	}
	
	/**
	 * 学生查看自己信息
	 * @param studentId
	 * @return
	 */
	@RequestMapping("/self/{studentId}")
	public ModelAndView selfInfo(@PathVariable("studentId") Integer studentId) {
		StudentInfo stu = studentInfoService.getStudentById(studentId);
		
		ModelAndView model = new ModelAndView();
		model.setViewName("/reception/self");
		model.addObject("self", stu);
		
		
		return model;
	}
	
	
	/**
	 * 学生修改密码
	 * @param pwd
	 * @param studentId
	 * @param response
	 * @throws IOException
	 */
	@RequestMapping("/reset/{pwd}/{studentId}")
	public void isResetPwd(
			@PathVariable("pwd") String pwd,
			@PathVariable("studentId") Integer studentId,
			HttpServletResponse response) throws IOException {
		logger.info("学生 "+studentId+" 修改密码");
		student.setStudentId(studentId);
		student.setStudentPwd(pwd);
		
		int row = studentInfoService.isResetPwdWithStu(student);
		
		if (row > 0) {
			response.getWriter().print("t");
		} else {
			response.getWriter().print("f");			
		}
	}
}

科目管理控制层:

@Controller
@SuppressWarnings("all")
public class CourseInfoHandler {
	@Autowired
	private CourseInfoService courseInfoService;
	@Autowired
	private GradeInfoService gradeInfoService;

	private Logger logger = Logger.getLogger(CourseInfoHandler.class);

	/**
	 * 获取科目信息
	 * 
	 * @param gradeId
	 *            系部编号
	 * @param division
	 *            分科情况
	 * @return
	 */
	@RequestMapping("/courses")
	public ModelAndView getCourses(@RequestParam(value = "gradeId", required = false) Integer gradeId,
			@RequestParam(value = "division", required = false) Integer division) {
		ModelAndView model = new ModelAndView();
		model.setViewName("/admin/course/courses");

		CourseInfo course = new CourseInfo();
		if (gradeId != null)
			course.getGrade().setGradeId(gradeId);
		if (division != null)
			course.setDivision(division);
		List<CourseInfo> courses = courseInfoService.getCourses(course);
		model.addObject("courses", courses);

		return model;
	}

	/**
	 * 根据科目编号获取学科信息
	 * 
	 * @param courseId
	 *            科目编号
	 * @return
	 */
	@RequestMapping("/course/{courseId}")
	public ModelAndView getCourseById(@PathVariable("courseId") Integer courseId) {
		ModelAndView model = new ModelAndView();
		model.setViewName("/admin/course/courseedit");

		CourseInfo course = courseInfoService.getCourseById(courseId);
		model.addObject("course", course);
		/** 获取所有系部列表 */
		List<GradeInfo> grades = gradeInfoService.getGrades();
		model.addObject("grades", grades);

		return model;
	}

	/**
	 * 添加/修改科目信息
	 * 
	 * @param courseId
	 *            科目编号
	 * @param isUpdate
	 *            标识是否为修改操作
	 * @param courseName
	 *            科目名称
	 * @param division
	 *            分科情况
	 * @param gradeId
	 *            系部编号
	 * @return
	 */
	@RequestMapping(value = "/course/course", method = RequestMethod.POST)
	public String isUpdateOrAddCourse(@RequestParam(value = "courseId", required = false) Integer courseId,
			@RequestParam(value = "isupdate", required = false) Integer isUpdate,
			@RequestParam("courseName") String courseName, @RequestParam("division") Integer division,
			@RequestParam("gradeId") Integer gradeId) {

		CourseInfo course = new CourseInfo();
		course.setCourseId(courseId);
		course.setCourseName(courseName);
		course.setDivision(division);
		GradeInfo grade = new GradeInfo();
		grade.setGradeId(gradeId);
		course.setGrade(grade);
		// 修改
		if (isUpdate != null) {
			int row = courseInfoService.isUpdateCourse(course);
		}
		// 添加
		else {
			int row = courseInfoService.isAddCourse(course);
		}
		return "redirect:/courses";
	}

	/**
	 * 删除科目
	 * 
	 * @param courseId
	 *            待删除科目编号
	 * @return
	 */
	@RequestMapping(value = "/course/{courseId}", method = RequestMethod.DELETE)
	public String isDelTeacher(@PathVariable("courseId") Integer courseId) {
		int row = courseInfoService.isDelCourse(courseId);
		return "redirect:/courses";
	}

	/**
	 * 预添加科目信息
	 * 
	 * @return
	 */
	@RequestMapping("/preAddCourse")
	public ModelAndView preAddCourse() {
		ModelAndView model = new ModelAndView();
		model.setViewName("/admin/course/courseedit");
		/** 获取系部集合 */
		List<GradeInfo> grades = gradeInfoService.getGrades();
		model.addObject("grades", grades);
		return model;
	}
}

源码获取:博客首页 "资源" 里下载! 

猜你喜欢

转载自blog.csdn.net/yuyecsdn/article/details/124442345