码迷,mamicode.com
首页 > 数据库 > 详细

ssm+mysql+jsp打造在线考试系统WeKnow-后端设计

时间:2019-02-01 18:55:57      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:lan   姓名   ati   account   查询   value   sele   sys   name   

一.登陆模块

前台提交账号和密码传到后台处理控制层

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-后端设计

标签:lan   姓名   ati   account   查询   value   sele   sys   name   

原文地址:https://www.cnblogs.com/cainame/p/10346613.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!