Eclipse+Java+SSM+Easyui实现网上考试系统


在这里插入图片描述

三、代码实现

=====================================================================

ExamController.java


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;

}

}

CustomException.java


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;

}

}

LessonServiceImpl.java


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);

}

}

QueryResultVo.java


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;

}

}

index.jsp


<%@ 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 ©: 水坚石青 版权所有

managerIndex.jsp


<%@ page language=“java” contentType=“text/html; charset=UTF-8”

pageEncoding=“UTF-8”%>

<%@ taglib prefix=“c” uri=“http://java.sun.com/jsp/jstl/core” %>

最后

金三银四到了,送上一个小福利!

image.png

image.png

专题+大厂.jpg

on" data-options=“iconCls:‘icon-cancel’,size:‘large’”>退出系统

CopyRight ©: 水坚石青 版权所有

managerIndex.jsp


<%@ 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)]

本文已被CODING开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】收录

  • 25
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值