源码获取:博客首页 "资源" 里下载!
本系统主要实现的功能有: 学生以及老师的注册登录,在线考试,错题查询,学生管理,问题管理,错题管理,错题查询,分数查询,试卷管 理,人工组卷。自动组卷,教师,班级,统计等等管理功能。
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: Springboot+ SpringMVC + MyBatis + ThymeLeaf + JavaScript + JQuery + Ajax + maven等等
@Controller
public class LoginController {
@Autowired
private StudentService studentService;
@Autowired
private TeacherService teacherService;
@Autowired
private QuestionService questionService;
@Autowired
private PaperService paperService;
@Autowired
private ClasseService classeService;
@Autowired
private RecordService recordService;
@RequestMapping("/")
public String view(Model model){
//查询所有用户
int teas=teacherService.queryCountAll();
int stus=studentService.queryCOuntALlstu();
int alllogers=teas+stus;
//统计试题
int allQues=questionService.queryCountAllQues();
//统计试卷
int allPaps=paperService.queryCountALlPaps();
model.addAttribute("allPaps",allPaps);
model.addAttribute("allQues",allQues);
model.addAttribute("alllogers",alllogers);
return "stage/prexam";
}
//后台切换到前台登录
@RequestMapping("/foreLogin")
public String foreLogin(){
return "stage/login";
}
//前台切换到后台登录
@RequestMapping("/backLogin")
public String backLogin(){
return "stage/loginx";
}
//后台教师登录验证
@ResponseBody
@RequestMapping("/backLogin/check")
public Object backCheck(Teacher teacher, HttpServletRequest request){
AjaxResult result=new AjaxResult();
HttpSession session=request.getSession();
Teacher teac=teacherService.check(teacher);
if(teac!=null){
session.setAttribute("logerd",teac);
result.setSuccess(true);
}else {
result.setSuccess(false);
}
return result;
}
@RequestMapping("/index")
public String index(Model model){
//查询所有用户
int teas=teacherService.queryCountAll();
int stus=studentService.queryCOuntALlstu();
int alllogers=teas+stus;
//统计试题
int allQues=questionService.queryCountAllQues();
//统计试卷
int allPaps=paperService.queryCountALlPaps();
List ScoreHStu=recordService.queryRankScoreRecord();
List AccHStu=recordService.queryRankAccRecord();
model.addAttribute("ScoreHStu",ScoreHStu);
model.addAttribute("AccHStu",AccHStu);
model.addAttribute("allPaps",allPaps);
model.addAttribute("allQues",allQues);
model.addAttribute("alllogers",alllogers);
return "index";
}
//前台学生登录考试
@ResponseBody
@RequestMapping("/foreCheck/check")
public Object foreCheck(Student student, HttpServletRequest request){
AjaxResult result=new AjaxResult();
HttpSession session=request.getSession();
Student stud=studentService.check(student);
if(stud!=null){
session.setAttribute("loger",stud);
result.setSuccess(true);
}else {
result.setSuccess(false);
}
return result;
}
//前台登录到展示页面
@RequestMapping("/indexprexam")
public String indexprexam(){
return "stage/prexamed";
}
//退出系统
@RequestMapping(value = {"*/logout","/logout","teacher/logout"})
public String logout(HttpSession session) {
//session里可能不止存放一个数据,移除麻烦,所以让其失效跟直接
session.invalidate();
return "redirect:/";
}
//学生注册
//去添加页面
@RequestMapping("/prexam/toAddStudent")
public String toAddStudent(Model model){
List allClasees = classeService.getAll();
model.addAttribute("allClasees",allClasees);
return "stage/studentAdd";
}
//添加具体操作
@RequestMapping("/prexam/AddStudent")
public String AddStudent(Student student){
studentService.AddStudent(student);
return "redirect:/foreLogin";
}
@RequestMapping("/zhao")
public String zhao(){
return "stage/zhao";
}
}
@Controller
@RequestMapping("/exam")
public class ExamController {
@Autowired
private ExamService examService;
@Autowired
private PaperService paperService;
@Autowired
private RecordService recordService;
//前台跳转
@RequestMapping("/toExam")
public String toExam(Model model){
List Exams = examService.getAll();
model.addAttribute("Exams",Exams);
return "exam/examplan";
}
@RequestMapping("/toError")
public String toError(Model model){
List Exams = examService.getAll();
model.addAttribute("Exams",Exams);
return "exam/error";
}
@RequestMapping("/tomError")
public String tomError(Model model){
List Exams = examService.getAll();
model.addAttribute("Exams",Exams);
return "exam/merror";
}
@RequestMapping("/toHist/{id}")
public String toHist(@PathVariable ("id") Integer id,Model model){
List records=recordService.queryAllExamById(id);
model.addAttribute("records",records);
return "exam/histplan";
}
//从其他页面跳转到home
@RequestMapping("/toHome")
public String tohome(){
return "redirect:/indexprexam";
}
//来到对应考试页面
@RequestMapping("/toDoExam/{id}")
public String toDoExam(@PathVariable ("id") Integer id,Model model,String examId,HttpServletRequest request){
HttpSession session=request.getSession();
Student stu = (Student) session.getAttribute("loger");
// if() {
// Record record=new Record();
// record.setStudentId(stu.getStudentId());
// record.setPaperId(id);
List ss= recordService.queryAllExamById(stu.getStudentId());
for (int i = 0; i < ss.size(); i++) {
if(ss.get(i).getPaperId() ==id ) {
return "redirect:/exam/tomError";
}
}
// }
List questionPapers = paperService.paperQueryALlQuestionByIdOrderByType(id);
int exId=Integer.parseInt(examId);
Exam examById = examService.getExamById(exId);
Paper paperName = paperService.queryPaperNameById(examById.getPaperId());
model.addAttribute("paperName",paperName);
model.addAttribute("examById",examById);
model.addAttribute("questionPapers",questionPapers);
return "exam/doExam";
}
//提交试卷
@RequestMapping("/submitExam")
public String submitExam(Integer paperId, Integer studentId, HttpServletRequest request){
List questionPapers = paperService.paperQueryALlQuestionByIdOrderByType(paperId);
List ans=new ArrayList<>();
List RightAns=new ArrayList<>();
for (QuestionPaper qb:questionPapers){
RightAns.add(qb.getQuestion().getQuestionOpright());
String parameter="";
String []parameters;
if(qb.getQuestion().getQuestionType().equals("y")){
parameters= request.getParameterValues("optionsSelect" + qb.getQuestionId());
if(parameters!=null) {
for(String s:parameters){
parameter+=s;
}
}
}else {
parameter = request.getParameter("optionsSelect" + qb.getQuestionId());
if(parameter==null) {
return "redirect:/exam/toError";
}
}
ans.add(parameter);
}
//核对答案得到成绩
int k=0; //哨兵
Double y=0.0; //正确数
int score=0; //得分
int a=0; //记录单选题个数
int b=0; //记录多选题个数
int c=0; //记录判断题个数
int totalScore=0;
for (QuestionPaper qb:questionPapers){
if(ans==null) {
break;
}
//若为单选题则正确+单选题分数
if(qb.getQuestion().getQuestionType().equals("x")){
if(ans.get(k).equals(RightAns.get(k))){
score+=qb.getPaper().getScoreSin();
y++;
}
a++;
k++;
}else if(qb.getQuestion().getQuestionType().equals("y")){
if(ans.get(k).equals(RightAns.get(k))){
score+=qb.getPaper().getScoreChe();
y++;
}
b++;
k++;
}else {
if(ans.get(k).equals(RightAns.get(k))){
score+=qb.getPaper().getScoreJug();
y++;
}
c++;
k++;
}
}
int scoreSin1 = questionPapers.get(0).getPaper().getScoreSin();
int scoreChe1 = questionPapers.get(0).getPaper().getScoreChe();
int scoreJug1 = questionPapers.get(0).getPaper().getScoreJug();
int bool=recordService.queryBooleanToscore(paperId);
if (bool==0){
totalScore=scoreSin1*a+scoreChe1*b+scoreJug1*c; //得到每张试卷总分
Toscore toscore=new Toscore();
toscore.setPaperId(paperId);
toscore.setToscore(totalScore);
recordService.AddToScore(toscore);
}
//保存答题记录
String answer = String.join(",", ans);
Paper paper = paperService.queryPaperNameById(paperId);
String paperName = paper.getPaperName();
Double recordAcc=y/k;
int recordScore=score;
Record record=new Record();
record.setRecordName(paperName);
record.setStudentId(studentId);
record.setPaperId(paperId);
record.setRecordAnswer(answer);
record.setRecordAcc(recordAcc);
record.setRecordScore(recordScore);
recordService.addRecord(record);
return "redirect:/exam/toExam";
}
/**
* 考试后台
* */
//查看所有考试安排后台
@RequestMapping("/getAllExam")
public String getAllExam(Model model){
List Exams = examService.getAllS();
model.addAttribute("Exams",Exams);
return "exam/backexamlist";
}
//去往考试添加页面
@RequestMapping("/toAddExam")
public String toAddExam(Model model){
List papers = paperService.getAll();
model.addAttribute("papers",papers);
return "exam/AddExam";
}
//添加操作
@RequestMapping("/addExam")
public String addExam(Exam exam, String examBegins,String examEnds) throws ParseException {
String t1 = examBegins.replace("T", " ");
String t2 = examEnds.replace("T", " ");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
Date begin = sdf.parse(t1);
Date end = sdf.parse(t2);
exam.setExamBegin(begin);
exam.setExamEnd(end);
examService.AddExam(exam);
return "redirect:/exam/getAllExam";
}
@RequestMapping("/deleteExam/{id}")
public String toEditExam(@PathVariable ("id") Integer id,Model model){
examService.deleteById(id);
return "redirect:/exam/getAllExam";
}
}
@Controller
@RequestMapping("/record")
public class RecordController {
@Autowired
RecordService recordService;
@Autowired
PaperService paperService;
@Autowired
ClasseService classeService;
//获取所有记录
@RequestMapping("/getAllRecord")
public String getAllRecord(Model model){
List records=recordService.queryAll();
model.addAttribute("records",records);
return "record/RecordList";
}
//删除记录
@RequestMapping("/deleteRecore/{id}")
public String deleteRecore(@PathVariable ("id") Integer id){
recordService.deleteById(id);
return "redirect:/record/getAllRecord";
}
//根据记录id获取试卷详情
@RequestMapping("/toShowExamHist/{id}")
public String toShowExamHist(@PathVariable ("id")Integer id,Model model){
//通过记录id查找试卷和答题记录
Integer papid=recordService.queryByRecordId(id);
String answers=recordService.queryAnsByRecordId(id);
//原始试卷
List questionPapers = paperService.paperQueryALlQuestionByIdOrderByType(papid);
//提交过的答案
List ans = Arrays.asList(answers.split(","));
model.addAttribute("questionPapers",questionPapers);
model.addAttribute("ans",ans);
//2020-1-26-20:40
return "record/showExamHist";
}
//显示所有班级记录
@RequestMapping("/showClaAcc")
public String showClaAcc(Model model){
//查询所有测试名称
List records=recordService.queryAllExam();
List claAccRes=new ArrayList<>();
//按照测试名称查询所有班级
for(Record rec:records){
//通过记录对应考试paperid查找总分***
int paperid=rec.getPaperId();
int toscore=recordService.queryToscore(paperid);
//记录考试名
String exaName=rec.getRecordName();
List clas=recordService.queryAllClass(exaName);
//初始化所有人和及格人数
int allScore=0;
int accScore=0;
for(Classe cla:clas){
int claId=cla.getClasseId();
//班级信息
Classe claName=classeService.queryClaNameById(claId);
RecordExam recordExam=new RecordExam();
recordExam.setClaId(claId);
recordExam.setExaName(exaName);
double setToscore=toscore*0.6;
recordExam.setToscore(setToscore);
//对应每一个班级,查询考试人数和及格人数
allScore=recordService.queryAllScore(recordExam);
//及格人数默认>60***
accScore=recordService.queryAccScore(recordExam);
double accre=(double)accScore/allScore;
//四舍五入保留2位
double acc = (double) Math.round(accre * 100) / 100;
ClaAcc claAcc=new ClaAcc();
claAcc.setExamName(exaName);
claAcc.setClaName(claName.getClasseName());
claAcc.setToscPer(allScore);
claAcc.setAcscPer(accScore);
claAcc.setAcc(acc);
//每个对象添加到list
claAccRes.add(claAcc);
}
}
model.addAttribute("claAccRes",claAccRes);
return "record/claAcc";
}
}
源码获取:博客首页 "资源" 里下载!