1. 程式人生 > >ssm+mysql+jsp打造在線考試系統WeKnow-後端設計

ssm+mysql+jsp打造在線考試系統WeKnow-後端設計

cor ring 2.3 test 調用服務 模塊 main.c bject inter

一.登陸模塊

前臺提交賬號和密碼傳到後臺處理控制層

1.1 首先是控制器

@RequestMapping(value="/studentLogin", method=RequestMethod.POST)
	public ModelAndView studentLogin(StudentInfo student, HttpServletRequest request) {
		ModelAndView model = new ModelAndView();
		StudentInfo loginStudent = studentInfoService.getStudentByAccountAndPwd(student.getStudentAccount());
		if(loginStudent == null || !student.getStudentPwd().equals(loginStudent.getStudentPwd())){
			model.setViewName("home/suc");
			return model;
		}
		request.getSession().setAttribute("loginStudent", loginStudent);
		System.out.println(request.getSession().getAttribute("loginStudent"));
		model.setViewName("home/suc");
		System.out.println("執行完畢");
		return model;
	}
}

1.2 在這裏會調用服務層

StudentInfo loginStudent = studentInfoService.getStudentByAccountAndPwd(student.getStudentAccount());

1.3 服務層接口

public StudentInfo getStudentByAccountAndPwd(String studentAccount);

1.4 服務層實現

public StudentInfo getStudentByAccountAndPwd(String studentAccount) {
return studentInfoMapper.getStudentByAccountAndPwd(studentAccount);//調用dao接口
}

1.5 數據層接口

public StudentInfo getStudentByAccountAndPwd(String studentAccount);

1.6 數據層實現

<mapper namespace="com.caizhen.weknow.dao.StudentInfoMapper">
	<!-- 定義resultMap -->
	<resultMap type="com.caizhen.weknow.domain.StudentInfo" id="queryStudent">
		<!-- 學號 -->
		<id column="studentId" property="studentId"/>
		<!-- 學生姓名 -->
		<result column="studentName" property="studentName"/>
		<!-- 學生賬號 -->
		<result column="studentAccount" property="studentAccount"/>
		<!-- 學生賬號密碼 -->
		<result column="studentPwd" property="studentPwd"/>
		<!-- 班級 -->
		<!-- 班級自身的屬性與數據庫字段的映射 --> 
		<association property="classInfo" javaType="com.caizhen.weknow.domain.ClassInfo">
			<id column="classId" property="classId"/>
			<result column="className" property="className"/>
		</association>
		<!-- 年級 -->
		<!-- 年級自身的屬性與數據庫字段的映射 --> 
		<association property="grade" javaType="com.caizhen.weknow.domain.GradeInfo">
			<id column="gradeId" property="gradeId"/>
			<result column="gradeName" property="gradeName"/>
		</association>
	</resultMap>
	<select id="getStudentByAccountAndPwd" parameterType="java.lang.String" resultMap="queryStudent">
		SELECT a.*,b.className,c.gradeId,c.gradeName FROM StudentInfo a
		INNER JOIN ClassInfo b ON a.classId=b.classId
		INNER JOIN GradeInfo c ON b.gradeId=c.gradeId
		WHERE studentAccount=#{studentAccount}
	</select>
</mapper>

二:考試中心模塊

<li><a id="examCenter-link" target="home" style="cursor: pointer;" 
href="willexams?
classId=${sessionScope.loginStudent.classInfo.classId }&
gradeId=${sessionScope.loginStudent.grade.gradeId }&
studentId=${sessionScope.loginStudent.studentId }"
>考試中心</a></li>

向url:willexams傳入三個參數:classId,gradeId,studentId

2.1進入控制器

@RequestMapping("/willexams")
	public ModelAndView getStudentWillExam(
			@RequestParam("classId") Integer classId,
			@RequestParam("gradeId") Integer gradeId,
			@RequestParam(value="studentId", required=false) Integer studentId) {
		ModelAndView model = new ModelAndView();
		model.setViewName("/home/examCenter");
//將classId和gradeId存入map集合中 Map<String, Object> map = new HashMap<String, Object>(); map.put("classId", classId); map.put("gradeId", gradeId); List<ExamPlanInfo> examPlans = examPlanInfoService.getStudentWillExam(map); model.addObject("examPlans", examPlans); model.addObject("gradeId", gradeId); return model; }

2.2 進入服務層接口

public List<ExamPlanInfo> getStudentWillExam(Map<String, Object> map);

2.3進入服務層實現層

public List<ExamPlanInfo> getStudentWillExam(Map<String, Object> map) {
		return examPlanInfoMapper.getStudentWillExam(map);
}

2.4 進入數據協議層

public List<ExamPlanInfo> getStudentWillExam(Map<String, Object> map);

2.5 進入數據實現層

<mapper namespace="com.caizhen.weknow.dao.ExamPlanInfoMapper">
	
	<resultMap type="com.caizhen.weknow.domain.ExamPlanInfo" id="queryWillExam">
		<id column="examPlanId" property="examPlanId"/>
		<result column="beginTime" property="beginTime"/>
		<!-- 科目 -->
		<association property="course" javaType="com.caizhen.weknow.domain.CourseInfo">
			<id column="courseId" property="courseId"/>
			<result column="courseName" property="courseName"/>
		</association>
		<!-- 班級 -->
		<association property="clazz" javaType="com.caizhen.weknow.domain.ClassInfo">
			<id column="classId" property="classId"/>
		</association>
		<!-- 試卷 -->
		<association property="examPaper" javaType="com.caizhen.weknow.domain.ExamPaperInfo">
			<id column="examPaperId" property="examPaperId"/>
			<result column="examPaperName" property="examPaperName"/>
			<result column="subjectNum" property="subjectNum"/>
			<result column="examPaperScore" property="examPaperScore"/>
			<result column="examPaperEasy" property="examPaperEasy"/>
			<result column="examPaperTime" property="examPaperTime"/>
		</association>
	</resultMap>

	<!-- 查詢學生待考信息 -->
	<!-- 考試安排表  examplaninfo a-->
	<!-- 班級信息表 classinfo  b-->
	<!-- 年級表 gradeinfo c -->
	<!-- 試卷表 exampaperinfo d -->
	<!-- 課程表 courseinfo e -->
	<!-- 需要的參數
	 1.a.* 考試安排表所有字段
	 2.d.examPaperName 試卷名稱
	 3.d.subjectNum 試題號
	 4.d.examPaperScore 試卷分數
	 5.d.examPaperEasy 試卷難易度
	 6.d.examPaperTime  考試時長
	 5.e.coure.name  課程名稱
	 -->
	<select id="getStudentWillExam" parameterType="java.util.Map" resultMap="queryWillExam">
		SELECT a.*,d.examPaperName,d.subjectNum,d.examPaperScore,d.examPaperEasy,d.examPaperTime,e.courseName FROM ExamPlanInfo a
		INNER JOIN ClassInfo b ON a.classId=b.classId
		INNER JOIN GradeInfo c ON b.gradeId=c.gradeId
		INNER JOIN ExamPaperInfo d ON a.examPaperId=d.examPaperId
		INNER JOIN CourseInfo e ON a.courseId=e.courseId
		WHERE a.classId=#{classId} AND b.gradeId=#{gradeId}
	</select>
</mapper>

2.6 定向到考試中心界面判斷exPlans中的條數是否大於0

<c:when test="${fn:length(examPlans) > 0 }">

如果不是則輸出頁面

<c:otherwise>
<div class="jumbotron">
<h1>暫無待考信息</h1>
<p>請等待教師分配</p>
</div>
</c:otherwise>

ssm+mysql+jsp打造在線考試系統WeKnow-後端設計