Java项目:在线考试系统(java+SSM+mysql+JSP)

运行环境:jdk1.8、Mysql5.7、Tomcat8.5、IDEA/Eclipse

功能简介:在线考试、历史回顾、个人成绩查询等。

管理员和教师功能有:学院管理、班级管理、课程管理、教师、学生管理、统计分析、试卷试题管理、考试安排管理、历史考试管理等

 

 

 

 

学生信息控制层:

@Controller
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private ClasseMapper classeMapper;
    @Autowired
    private StudentService studentService;
//查看所有学生
    @RequestMapping("/getAllStudent")
    public String getAllStudent(Model model){
        List<Student> students = studentService.getAll();
        model.addAttribute("students",students);
        return "student/studentList";
    }

//修改编辑功能,先获取该id得学生信息
    @RequestMapping("/{id}")
    public String updateStudent(@PathVariable("id") Integer id,Model model){
        Student student=studentService.getStudentById(id);
        List<Classe> classes = classeMapper.queryAll();
        model.addAttribute("classes",classes);
        model.addAttribute("student",student);
        return "student/studentEdit";
    }
//更改学生信息
    @RequestMapping("/editStudent")
    public String EditStudent(Student student){
        studentService.EditStudent(student);
        return "redirect:/student/getAllStudent";
    }
//删除学生
    @RequestMapping("/deleteStudent/{id}")
    public String deleteStudent(@PathVariable("id") Integer id){
        studentService.deleteById(id);
        return "redirect:/student/getAllStudent";
    }
}

登录信息控制层:

@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<Record> ScoreHStu=recordService.queryRankScoreRecord();
        List<Record> 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<Classe> 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("/question")
public class QuestionController {
    @Autowired
    private QuestionService questionService;
    @Autowired
    private TeacherService teacherService;
    @Autowired
    private PaperService paperService;
    //查看所有试题 pagesize控制每页数据条数
    @RequestMapping("/getAllQuestion")
    public String getAllQuestion(Question question,@RequestParam(defaultValue = "1") int pageNum,
                                 @RequestParam(defaultValue = "4") int pageSize,
                                 Model model){
        //查找所有题目课程和所有类型,且去重
        List<Question> questionCourses=questionService.queryAllCourse();
        questionCourses.add(new Question("bug","all"));
        List<Question> questionTypes=questionService.queryAllType();
        questionTypes.add(new Question("k","bug"));
        String questionCourseBef = question.getQuestionCourse();
        String questionCourseresRes="";
        if(questionCourseBef==null){
            //默认查询所有
            questionCourseresRes="all";
        }else {
            questionCourseresRes=questionCourseBef;
        }
        //若是第一次查询则用上次提交的表单中的类型、课程,若是第二次查询则延用上次类型
        String questionTypeBef=question.getQuestionType();
        String questionTypesRes="";
        if(questionTypeBef==null){
            //默认查询所有
            questionTypesRes="k";
        }else {
            questionTypesRes=questionTypeBef;
        }
        List<Question> questionids=paperService.queryALlQuestionId();
        List<Integer> quesIds=new ArrayList<>();
        for(Question qid:questionids){
            quesIds.add(qid.getQuestionId());
        }
        model.addAttribute("quesIds",quesIds);

        PageHelper.startPage(pageNum,pageSize);//这行是重点,表示从pageNum页开始,每页pageSize条数据
        List<Question> questions = questionService.getAll(question);
        PageInfo<Question> pageInfo = new PageInfo<Question>(questions);
        model.addAttribute("questionCourseresRes",questionCourseresRes);
        model.addAttribute("questionTypesRes",questionTypesRes);
        model.addAttribute("questionTypes",questionTypes);
        model.addAttribute("questionCourses",questionCourses);
        model.addAttribute("pageInfo",pageInfo);
        return "question/questionList";
    }
//试题添加或者修改操作,先去添加页面
    @RequestMapping("/toAddQuestion")
    public String toAddQuestion(Model model){
        List<Question> questionCourses=questionService.queryAllCourse();
        List<Question> questionTypes=questionService.queryAllType();
        model.addAttribute("questionTypes",questionTypes);
        model.addAttribute("questionCourses",questionCourses);
        return "question/questionAdd";
    }

    //添加具体操作
    @RequestMapping("/addQuestion")
    public String addQuestion(Question question){
        questionService.addQuestion(question);
        return "redirect:/question/getAllQuestion";
    }

//试题去修改页面
    @RequestMapping("/toEditQuestion/{id}")
    public String toEditQuestion(@PathVariable("id") Integer id,Model model){
        List<Question> questionCourses=questionService.queryAllCourse();
        List<Question> questionTypes=questionService.queryAllType();
        Question question=questionService.getQuestionById(id);
        model.addAttribute("questionTypes",questionTypes);
        model.addAttribute("questionCourses",questionCourses);
        model.addAttribute("question",question);
        return "question/questionEdit";
    }

    //修改具体操作
    @RequestMapping("/EditQuestion")
    public String EditQuestion(Question question){
        questionService.editQuestion(question);
        return "redirect:/question/getAllQuestion";
    }

    //试题删除
    @RequestMapping("/deleteQuestion/{id}")
    public String deleteQuestionById(@PathVariable("id") Integer id){
        questionService.deleteQuestionById(id);
        return "redirect:/question/getAllQuestion";
    }

}

猜你喜欢

转载自blog.csdn.net/m0_59687645/article/details/121762625