一.登陸模塊
前台提交賬號和密碼傳到后台處理控制層
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>
三:歷史考試模塊
1.前台
<!-- 考試歷史 -->
<li><a id="mineCenter-link" target="home" style="cursor: pointer;" href="history/${sessionScope.loginStudent.studentId }" studentId="${sessionScope.loginStudent.studentId }">考試歷史</a></li>
1.1 前台狀態校驗
<script type="text/javascript">
$(function() {
//考試中心狀態判斷
$("#examCenter-link, #mineCenter-link").click(function() {
//判斷是否登錄
var studetnId = $(this).attr("studentId");
//如果學生號為空
if(studetnId.trim() == "" || studetnId == null) {
zeroModal.show({
title: "提示",
content: "登錄后才能查看",
width : '200px',
height : '130px',
overlay : false,
ok : true,
onClosed : function() {
location.reload();
}
});
return false;
}
});
2.后台
2.1 如果學生成功登陸后點擊歷史考試(控制層)
@Controller
public class ExamHistoryInfoHandler {
@Autowired
private ExamHistoryPaperService examHistoryPaperService;
@RequestMapping("/historys")
public ModelAndView examHistorys() {
List<ExamHistoryInfo> historys = examHistoryPaperService.getExamHistoryToTeacher();
ModelAndView model = new ModelAndView("admin/examHistorys");
model.addObject("historys", historys);
return model;
}
}
2.2 服務層
private ExamHistoryPaperService examHistoryPaperService;
服務層
public interface ExamHistoryPaperService {
//查詢考試歷史信息,針對前台學生查詢
public List<ExamHistoryPaper> getExamHistoryToStudent(int studentId);
public int isAddExamHistory(Map<String, Object> map);
public int getHistoryInfoWithIds(Map<String, Object> map);
public List<ExamHistoryInfo> getExamHistoryToTeacher();
}
2.3 服務實現層
@Service
public class ExamHistoryPaperServiceImpl implements ExamHistoryPaperService {
@Autowired
private ExamHistoryPaperMapper examHistoryPaperMapper;
public List<ExamHistoryPaper> getExamHistoryToStudent(int studentId) {
return examHistoryPaperMapper.getExamHistoryToStudent(studentId);
}
public int isAddExamHistory(Map<String, Object> map) {
return examHistoryPaperMapper.isAddExamHistory(map);
}
public int getHistoryInfoWithIds(Map<String, Object> map) {
return examHistoryPaperMapper.getHistoryInfoWithIds(map);
}
public List<ExamHistoryInfo> getExamHistoryToTeacher() {
return examHistoryPaperMapper.getExamHistoryToTeacher();
}
}
2.4 數據接口層
public interface ExamHistoryPaperMapper {
//查詢考試歷史信息,針對前台學生查詢
public List<ExamHistoryPaper> getExamHistoryToStudent(int studentId);
public int isAddExamHistory(Map<String, Object> map);
public int getHistoryInfoWithIds(Map<String, Object> map);
//查詢考試歷史信息,針對后台教師查詢
public List<ExamHistoryInfo> getExamHistoryToTeacher();
}
2.5 數據實現層
<mapper namespace="com.caizhen.weknow.dao.ExamHistoryPaperMapper">
<resultMap type="com.caizhen.weknow.domain.ExamHistoryInfo" id="queryExamHistoryToStudentResultMap">
<id column="historyId" property="historyId"/>
<result column="examScore" property="examScore"/>
<association property="examPaper" javaType="com.caizhen.weknow.domain.ExamPaperInfo">
<id column="examPaperId" property="examPaperId"/>
<result column="examPaperName" property="examPaperName"/>
<result column="examPaperScore" property="examPaperScore"/>
<result column="subjectNum" property="subjectNum"/>
</association>
</resultMap>
<!-- 查詢考試歷史信息,針對前台學生查詢 -->
<select id="getExamHistoryToStudent" parameterType="int" resultType="ExamHistoryPaper">
SELECT
a.historyId,a.examScore,b.examPaperId,b.examPaperName,b.examPaperScore,b.subjectNum,c.beginTime
FROM ExamHistoryInfo a
LEFT JOIN examPaperInfo b ON a.examPaperId=b.exampaperId
LEFT JOIN examPlanInfo c ON b.examPaperId=c.examPaperId
WHERE studentId=#{studentId}
</select>
<!-- 新增歷史記錄 -->
<insert id="isAddExamHistory" parameterType="java.util.Map">
INSERT INTO ExamHistoryInfo VALUES(NULL, #{studentId}, #{examPaperId}, #{examScore});
</insert>
<select id="getHistoryInfoWithIds" parameterType="java.util.Map" resultType="int">
SELECT COUNT(*) FROM ExamHistoryInfo WHERE studentId=#{studentId} AND examPaperId=#{examPaperId}
</select>
<resultMap type="com.caizhen.weknow.domain.ExamHistoryInfo" id="queryExamHistoryToTeacherResultMap">
<id column="historyId" property="historyId"/>
<result column="examScore" property="examScore"/>
<association property="examPaper" javaType="com.caizhen.weknow.domain.ExamPaperInfo">
<id column="examPaperId" property="examPaperId"/>
<result column="examPaperName" property="examPaperName"/>
<result column="examPaperScore" property="examPaperScore"/>
<result column="subjectNum" property="subjectNum"/>
</association>
<association property="student" javaType="com.caizhen.weknow.domain.StudentInfo">
<id column="studentId" property="studentId"/>
<result column="studentName" property="studentName"/>
</association>
</resultMap>
<!-- 查詢考試歷史信息,針對后台教師查詢 -->
<select id="getExamHistoryToTeacher" resultMap="queryExamHistoryToTeacherResultMap">
SELECT
a.historyId,a.examScore,b.examPaperId,b.examPaperName,b.examPaperScore,b.subjectNum,d.studentId,d.studentName
FROM ExamHistoryInfo a
INNER JOIN examPaperInfo b ON a.examPaperId=b.exampaperId
LEFT JOIN StudentInfo d ON a.studentId=d.studentId;
</select>
</mapper>
