=====================================================================
package controller;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpSession;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import po.Exam;
import po.Questions;
import po.QuestionsCustom;
import po.Student;
import po.Studentresult;
import po.StudentresultCustom;
import po.Taoti;
import service.QuestionsService;
import service.ResultService;
import service.StudentService;
import service.TaotiService;
@Controller
public class ExamController {
@Autowired
private TaotiService taotiService;
@Autowired
private QuestionsService questionsService;
@Autowired
private StudentService studentService;
@Autowired
private ResultService resultService;
@RequestMapping(“/toExam.action”)
public String toExam() throws Exception{
return “/exam”;
}
@RequestMapping(“/toExamPage.action”)
public ModelAndView toExamPage(Integer lessonid) throws Exception{
ModelAndView modelAndView=new ModelAndView();
List list = taotiService.findListByLessonid(lessonid);
if (list.size()>0) {
Integer length=list.size();
Integer index=(int) (Math.random()*(length-1));
Taoti taoti=list.get(index);
List list2 = questionsService.findListByTaotiid(taoti.getId());
modelAndView.addObject(“list”, list2);
}else {
modelAndView.addObject(“list”, null);
}
modelAndView.setViewName(“/examPage”);
return modelAndView;
}
@RequestMapping(“/postExam.action”)
public ModelAndView postExam(Exam exam,HttpSession session) throws Exception{
ModelAndView modelAndView=new ModelAndView();
Studentresult studentresult=new Studentresult();
Map<Integer, String> map = exam.getAnswerMap();
Set keySet=map.keySet();
Iterator it=keySet.iterator();
Integer singleGrade=0;
Integer doubleGrade=0;
Integer taotiId=null;
while(it.hasNext()) {
Integer key=it.next();
String value=map.get(key);
Questions questions = questionsService.findById(key);
if(taotiId == null) {
taotiId=questions.getTaotiid();
}
if(questions.getType().equals(“单选”)) {
if(questions.getAnswer().equals(value)) {
singleGrade+=10;
}
}else {
if(questions.getAnswer().equals(value)) {
doubleGrade+=20;
}
}
}
Integer totalGrade=singleGrade+doubleGrade;
Taoti taoti = taotiService.fintOneById(taotiId);
String examnumber=“CN”;
SimpleDateFormat simpleDateFormat=new SimpleDateFormat(“yyyyMMdd”);
Date date=new Date();
String strD = simpleDateFormat.format(date);
Object studentName = session.getAttribute(“studentName”);
String studentId=null;
if(studentName!=null) {
String studentName2=studentName.toString();
Student student = studentService.findOne(studentName2);
studentId=student.getId().toString();
}
examnumber=examnumber+strD+studentId;
studentresult.setExamnumber(examnumber);
studentresult.setLessonid(taoti.getLessonid());
studentresult.setResingle(singleGrade);
studentresult.setResmore(doubleGrade);
studentresult.setRestotal(totalGrade);
studentresult.setCreatetime(new Timestamp(new Date().getTime()));
if(session.getAttribute(“xiaowutoken”)!=null) {
resultService.addOne(studentresult);
session.removeAttribute(“xiaowutoken”);
}
List questionsCustoms = questionsService.findListByTaotiid(taotiId);
StudentresultCustom studentresultCustom=new StudentresultCustom();
BeanUtils.copyProperties(studentresult, studentresultCustom);
studentresultCustom.setLessonname(questionsCustoms.get(0).getLessonName());
modelAndView.setViewName(“/examResult”);
modelAndView.addObject(“studentresult”, studentresultCustom);
return modelAndView;
}
}
package exception;
public class CustomException extends Exception {
/**
*/
private static final long serialVersionUID = 1L;
private String message;
public CustomException(String message) {
super(message);
this.message=message;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
package serviceImpl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import mapper.LessonMapper;
import mapper.LessonMapperCustom;
import po.Lesson;
import po.LessonExample;
import po.Pagination;
import service.LessonService;
public class LessonServiceImpl implements LessonService {
@Autowired
private LessonMapper lessonMapper;
@Autowired
private LessonMapperCustom lessonMapperCustom;
public List getListByLimit(Pagination pagination) throws Exception {
pagination.setStartPage((pagination.getPage()-1)*pagination.getRows());
return lessonMapperCustom.getListByLimit(pagination);
}
public List getList() throws Exception {
LessonExample example=new LessonExample();
return lessonMapper.selectByExample(example);
}
@Transactional
public void deleteOneById(Integer id) {
lessonMapper.deleteByPrimaryKey(id);
}
@Transactional
public void addOne(Lesson lesson) {
lessonMapper.insertSelective(lesson);
}
}
package vo;
import po.Pagination;
import po.QueryResult;
import po.StudentresultCustom;
public class QueryResultVo {
private Pagination pagination;
private QueryResult queryResult;
public Pagination getPagination() {
return pagination;
}
public void setPagination(Pagination pagination) {
this.pagination = pagination;
}
public QueryResult getQueryResult() {
return queryResult;
}
public void setQueryResult(QueryResult queryResult) {
this.queryResult = queryResult;
}
}
<%@ page language=“java” contentType=“text/html; charset=UTF-8”
pageEncoding=“UTF-8”%>
href=“${pageContext.request.contextPath }/easyui/themes/default/easyui.css”>
href=“${pageContext.request.contextPath }/easyui/themes/icon.css”>
营 养 在 线 考 试 网
当 前 学 生:${sessionScope.studentName }
CopyRight ©: 水坚石青 版权所有
<%@ page language=“java” contentType=“text/html; charset=UTF-8”
pageEncoding=“UTF-8”%>
<%@ taglib prefix=“c” uri=“http://java.sun.com/jsp/jstl/core” %>
最后
金三银四到了,送上一个小福利!
on" data-options=“iconCls:‘icon-cancel’,size:‘large’”>退出系统
CopyRight ©: 水坚石青 版权所有
<%@ page language=“java” contentType=“text/html; charset=UTF-8”
pageEncoding=“UTF-8”%>
<%@ taglib prefix=“c” uri=“http://java.sun.com/jsp/jstl/core” %>
最后
金三银四到了,送上一个小福利!
[外链图片转存中…(img-GLd6I9a5-1714288063733)]
[外链图片转存中…(img-on0kP9QK-1714288063733)]
[外链图片转存中…(img-YfAZ4h30-1714288063733)]