Java项目:ssm学生学籍管理系统

发布于:2022-12-22 ⋅ 阅读:(224) ⋅ 点赞:(0)

作者主页:夜未央5788

 简介:Java领域优质创作者、Java项目、学习资料、技术互助

文末获取源码

项目介绍

SSM项目-学生学籍管理系统。该项目分管理员、老师、学生三种用户角色。每种角色分别对应不同的菜单;

以下分别介绍各个角色对应的功能模块:

管理员角色:

- 用户登录和退出
- 权限控制
- 系统管理
- 专业管理
- 班级管理
- 学生管理
- 老师管理
- 课程管理
- 开课管理
- 用户管理

老师角色:

- 老师管理
- 成绩管理
- 学生查询

学生角色:

- 学生管理
- 选课管理

- 成绩查询

技术路线

- 开发工具:IDEA 2020.1

- 技术框架:Spring、SpringMVC、MyBatis
- Web容器:Tomcat 8.5.7
- 数据库:MySQL 5.7
- 前端UI框架:LayUI

- 项目管理:Maven 3.6.3

使用说明

1. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;

若为maven项目,导入成功后请执行maven clean;maven install命令,下载所需jar包;

2. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置
4. 配置tomcat,然后运行项目,输入localhost:8080 登录

运行截图

 

 

 

 

 

 

 

 

相关代码 

CourseController

package com.yanzhen.controller;

import com.yanzhen.entity.Course;
import com.yanzhen.service.CourseService;
import com.yanzhen.utils.MapControl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/course")
public class CourseController {

    private static final String LIST = "course/list";
    private static final String ADD = "course/add";
    private static final String UPDATE = "course/update";

    @Autowired
    private CourseService courseService;

    //跳转添加页面
    @GetMapping("/add")
    public String create() {
        return ADD;
    }

    //添加操作
    @PostMapping("/create")
    @ResponseBody
    public Map<String, Object> create(@RequestBody Course course) {
        int result = courseService.create(course);
        if (result <= 0) {
            return MapControl.getInstance().error().getMap();
        }
        return MapControl.getInstance().success().getMap();
    }

    //根据id删除
    @PostMapping("/delete/{id}")
    @ResponseBody
    public Map<String, Object> delete(@PathVariable("id") Integer id) {
        int result = courseService.delete(id);
        if (result <= 0) {
            return MapControl.getInstance().error().getMap();
        }
        return MapControl.getInstance().success().getMap();
    }

    //批量删除
    @PostMapping("/delete")
    @ResponseBody
    public Map<String, Object> delete(String ids) {
        int result = courseService.delete(ids);
        if (result <= 0) {
            return MapControl.getInstance().error().getMap();
        }
        return MapControl.getInstance().success().getMap();
    }

    //修改操作
    @PostMapping("/update")
    @ResponseBody
    public Map<String, Object> update(@RequestBody Course course) {
        int result = courseService.update(course);
        if (result <= 0) {
            return MapControl.getInstance().error().getMap();
        }
        return MapControl.getInstance().success().getMap();
    }

    //根据id删除,跳转修改页面
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") Integer id, ModelMap modelMap) {
        //查询出要修改的课程信息,存储到request域
        Course course = courseService.detail(id);
        modelMap.addAttribute("course", course);
        return UPDATE;
    }

    //查询所有
    @PostMapping("/query")
    @ResponseBody
    public Map<String, Object> query(@RequestBody Course course) {
        List<Course> list = courseService.query(course);
        //查询总记录条数
        Integer count = courseService.count(course);
        return MapControl.getInstance().success().page(list, count).getMap();
    }

    //跳转列表页面
    @GetMapping("/list")
    public String list() {
        return LIST;
    }

}

IndexController

package com.yanzhen.controller;

import com.yanzhen.entity.*;
import com.yanzhen.service.*;
import com.yanzhen.utils.MD5Utils;
import com.yanzhen.utils.MapControl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class IndexController {

    @Autowired
    UserService userService;
    @Autowired
    TeacherService teacherService;
    @Autowired
    StudentService studentService;
    @Autowired
    ClazzService clazzService;
    @Autowired
    SubjectService subjectService;
    @Autowired
    CourseService courseService;
    @Autowired
    SectionService sectionService;
    @Autowired
    ScoreService scoreService;

    //跳转系统主页
    @GetMapping("/index")
    public String login() {
        return "index";
    }

    //跳转用户基本信息页面
    @GetMapping("/info")
    public String info() {
        return "info";
    }

    //跳转修改密码页面
    @GetMapping("/pwd")
    public String pwd() {
        return "pwd";
    }

    //修改密码 根据旧密码来修改密码
    @PostMapping("/pwd")
    @ResponseBody
    public Map<String,Object> pwd(String sourcePwd,String newPwd,String type,Integer id) {
        //先判断类型
        if("1".equals(type)) {
            User user = userService.detail(id);
            //比较原密码是否相同 注意:原密码也要加密后再进行比较,因为数据库中存储的是加密后的密码
            if(user.getUserPwd().equals(MD5Utils.getMD5(sourcePwd))) {
                User entity = new User();
                entity.setId(id);
                entity.setUserPwd(MD5Utils.getMD5(newPwd)); //主要要加密
                int result = userService.update(entity);
                if(result <= 0) {
                    return MapControl.getInstance().error().getMap();
                } else {
                    return MapControl.getInstance().success().getMap();
                }
            } else {
                return MapControl.getInstance().error("原密码错误").getMap();
            }
        }
        if("2".equals(type)) {
            Teacher teacher = teacherService.detail(id);
            //比较原密码
            if(teacher.getTeacherPwd().equals(MD5Utils.getMD5(sourcePwd))) {
                Teacher entity = new Teacher();
                entity.setId(id);
                entity.setTeacherPwd(MD5Utils.getMD5(newPwd));
                int result = teacherService.update(entity);
                if(result <= 0) {
                    return MapControl.getInstance().error().getMap();
                } else {
                    return MapControl.getInstance().success().getMap();
                }
            } else {
                return MapControl.getInstance().error("原密码错误").getMap();
            }
        }
        if("3".equals(type)) {
            Student student = studentService.detail(id);
            //比较原密码
            if(student.getStuPwd().equals(MD5Utils.getMD5(sourcePwd))) {
                Student entity = new Student();
                entity.setId(id);
                entity.setStuPwd(MD5Utils.getMD5(newPwd));
                int result = studentService.update(entity);
                if(result <= 0) {
                    return MapControl.getInstance().error().getMap();
                } else {
                    return MapControl.getInstance().success().getMap();
                }
            } else {
                return MapControl.getInstance().error("原密码错误").getMap();
            }
        }

        return MapControl.getInstance().error().getMap();
    }

    //跳转系统主页(数据概览)
    @GetMapping("/main")
    public String main(ModelMap modelMap) {
        //1.系统数据概览
        List<Clazz> clazzes = clazzService.query(null);
        List<Subject> subjects = subjectService.query(null);
        List<Teacher> teachers = teacherService.query(null);
        List<Course> courses = courseService.query(null);
        List<Section> sections = sectionService.query(null);
        List<Student> students = studentService.query(null);
        modelMap.addAttribute("clazzCnt",clazzes.size());
        modelMap.addAttribute("subjectCnt",subjects.size());
        modelMap.addAttribute("teacherCnt",teachers.size());
        modelMap.addAttribute("courseCnt",courses.size());
        modelMap.addAttribute("studentCnt",students.size());
        modelMap.addAttribute("sectionCnt",sections.size());

        //2.班级学生数量
        List<Map<String,Object>> mapList = new ArrayList<>();
        for(Clazz clazz : clazzes) {
            Map<String,Object> map = new HashMap<>();
            map.put("name",clazz.getClazzName()); //设置班级名称
            int cnt = 0;
            //统计学生数量
            for(Student student : students) {
                if(student.getClazzId() == clazz.getId()) {
                    cnt++;
                }
            }
            map.put("cnt",cnt); //设置学生数量
            mapList.add(map);
        }
        modelMap.addAttribute("mapList",mapList);

        //3.查询各科平均成绩(根据专业查询各科平均成绩)
        List<HashMap> mapList2 = scoreService.queryAvgScoreBySection();
        modelMap.addAttribute("mapList2",mapList2);

        return "main";
    }

}

ScoreController

package com.yanzhen.controller;

import com.yanzhen.entity.Course;
import com.yanzhen.entity.Score;
import com.yanzhen.entity.Section;
import com.yanzhen.entity.Student;
import com.yanzhen.service.CourseService;
import com.yanzhen.service.ScoreService;
import com.yanzhen.service.SectionService;
import com.yanzhen.utils.MapControl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/score")
public class ScoreController {

    @Autowired
    private ScoreService scoreService;
    @Autowired
    private CourseService courseService;
    @Autowired
    private SectionService sectionService;

    //添加操作
    @PostMapping("/create")
    @ResponseBody
    public Map<String, Object> create(String sectionIds, String courseIds, HttpSession session) {
        Student student = (Student) session.getAttribute("user");
        int result = scoreService.create(sectionIds, courseIds, student.getId());
        if (result <= 0) {
            return MapControl.getInstance().error().getMap();
        }
        return MapControl.getInstance().success().getMap();
    }

    //修改操作
    @PostMapping("/update")
    @ResponseBody
    public Map<String, Object> update(Score score) {
        int result = scoreService.update(score);
        if (result <= 0) {
            return MapControl.getInstance().error().getMap();
        }
        return MapControl.getInstance().success().getMap();
    }

    //根据id查询
    @PostMapping("/detail/{id}")
    @ResponseBody
    public Map<String, Object> detail(@PathVariable("id") Integer id) {
        Score score = scoreService.detail(id);
        if (score == null) {
            return MapControl.getInstance().nodata().getMap();
        }
        return MapControl.getInstance().success().put("data", score).getMap();
    }

    //查询所有
    @PostMapping("/query")
    @ResponseBody
    public Map<String, Object> query(Score score) {
        List<Score> list = scoreService.query(score);
        return MapControl.getInstance().success().put("data", list).getMap();
    }

    //跳转查询成绩页面
    @GetMapping("/student_score")
    public String student_score() {
        return "score/student_score";
    }

    //查询学生成绩
    @PostMapping("/query_student_score")
    @ResponseBody
    public Map<String, Object> query_student_score(HttpSession session) {
        //从session中获取
        Student student = (Student) session.getAttribute("user");
        Score score = new Score();
        score.setStuId(student.getId());
        //查询成绩
        List<Score> scores = scoreService.query(score);
        //查询课程信息
        List<Course> courses = courseService.query(null);
        //查询开课信息
        List<Section> sections = sectionService.query(null);

        scores.forEach(entity -> {
            courses.forEach(course -> {
                //判断该成绩表中的courseId与课程表的id是否一致
                if (entity.getCourseId() == course.getId()) {
                    entity.setCourse(course);
                }
            });
            sections.forEach(section -> {
                //判断该成绩的开课id是否与开课的id一致
                if (entity.getSectionId() == section.getId()) {
                    entity.setSection(section);
                }
            });
            entity.setStudent(student);
        });
        return MapControl.getInstance().success().put("data", scores).getMap();
    }
}

StudentController

package com.yanzhen.controller;

import com.yanzhen.entity.Clazz;
import com.yanzhen.entity.Student;
import com.yanzhen.entity.Subject;
import com.yanzhen.entity.Teacher;
import com.yanzhen.service.ClazzService;
import com.yanzhen.service.StudentService;
import com.yanzhen.service.SubjectService;
import com.yanzhen.utils.MapControl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/student")
public class StudentController {

    private static final String LIST = "student/list";
    private static final String ADD = "student/add";
    private static final String UPDATE = "student/update";

    @Autowired
    private StudentService studentService;
    @Autowired
    private SubjectService subjectService;
    @Autowired
    private ClazzService clazzService;

    //跳转添加页面
    @GetMapping("/add")
    public String create(ModelMap modelMap) {
        //查询所有的专业,存储到request域
        List<Subject> subjects = subjectService.query(null);
        modelMap.addAttribute("subjects", subjects);
        return ADD;
    }

    //添加操作
    @PostMapping("/create")
    @ResponseBody
    public Map<String, Object> create(@RequestBody Student student) {
        //设置学生的状态
        student.setStatus(Student.StatusType.type_1);
        int result = studentService.create(student);
        if (result <= 0) {
            return MapControl.getInstance().error().getMap();
        }
        return MapControl.getInstance().success().getMap();
    }

    //根据id查询
    @PostMapping("/delete/{id}")
    @ResponseBody
    public Map<String, Object> delete(@PathVariable("id") Integer id) {
        int result = studentService.delete(id);
        if (result <= 0) {
            return MapControl.getInstance().error().getMap();
        }
        return MapControl.getInstance().success().getMap();
    }

    //删除操作
    @PostMapping("/delete")
    @ResponseBody
    public Map<String, Object> delete(String ids) {
        int result = studentService.delete(ids);
        if (result <= 0) {
            return MapControl.getInstance().error().getMap();
        }
        return MapControl.getInstance().success().getMap();
    }

    //修改操作
    @PostMapping("/update")
    @ResponseBody
    public Map<String, Object> update(@RequestBody Student student) {
        int result = studentService.update(student);
        if (result <= 0) {
            return MapControl.getInstance().error().getMap();
        }
        return MapControl.getInstance().success().getMap();
    }

    //根据id查询,跳转修改页面
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") Integer id, ModelMap modelMap) {
        //查询出要修改的学生的信息
        Student student = studentService.detail(id);
        //查询所有的专业
        List<Subject> subjects = subjectService.query(null);
        //将查询出来的数据存储到request域,实现表单回显
        modelMap.addAttribute("student", student);
        modelMap.addAttribute("subjects", subjects);
        return UPDATE;
    }

    //查询所有
    @PostMapping("/query")
    @ResponseBody
    public Map<String, Object> query(@RequestBody Student student) {
        //查询所有的学生信息
        List<Student> list = studentService.query(student);
        //查询所有的专业
        List<Subject> subjects = subjectService.query(null);
        //查询所有的班级
        List<Clazz> clazzes = clazzService.query(null);
        //设置关联
        list.forEach(entity -> {
            subjects.forEach(subject -> {
                //判断学生表中的subjectId和专业表的id是否一致
                if (subject.getId() == entity.getSubjectId()) {
                    entity.setSubject(subject);
                }
            });
            clazzes.forEach(clazz -> {
                //判断学生表中的clazzId和班级表的id是否一致
                if (clazz.getId() == entity.getClazzId()) {
                    entity.setClazz(clazz);
                }
            });
        });
        //查询总记录条数
        Integer count = studentService.count(student);
        return MapControl.getInstance().success().page(list, count).getMap();
    }

    //跳转列表页面
    @GetMapping("/list")
    public String list() {
        return LIST;
    }

    //跳转查询学生页面
    @GetMapping("/teacher_student")
    public String teacher_student(ModelMap modelMap, HttpSession session) {
        //查询所有的专业
        List<Subject> subjects = subjectService.query(null);
        //查询所有的班级
        List<Clazz> clazzes = clazzService.query(null);
        Teacher teacher = (Teacher) session.getAttribute("user");
        modelMap.addAttribute("subjects", subjects);
        modelMap.addAttribute("clazzes", clazzes);
        modelMap.addAttribute("teacher", teacher);
        return "student/teacher_student";
    }

    //老师查询学生
    @PostMapping("/teacher_student")
    @ResponseBody
    public Map<String, Object> teacher_student(Integer clazzId, Integer subjectId, ModelMap modelMap, HttpSession session) {
        Teacher teacher = (Teacher) session.getAttribute("user");
        List<Student> students = studentService.queryStudentByTeacher(teacher.getId(), clazzId, subjectId);
        List<Subject> subjects = subjectService.query(null);
        List<Clazz> clazzes = clazzService.query(null);
        //设置关联
        students.forEach(entity -> {
            subjects.forEach(subject -> {
                //判断学生表的subjectId和专业表的id是否一致
                if (subject.getId() == entity.getSubjectId()) {
                    entity.setSubject(subject);
                }
            });
            clazzes.forEach(clazz -> {
                //判断学生表的clazzId和班级表的id是否一致
                if (clazz.getId() == entity.getClazzId()) {
                    entity.setClazz(clazz);
                }
            });
        });
        return MapControl.getInstance().success().add("data", students).getMap();
    }
}

如果也想学习本系统,下面领取。关注并回复:014ssm 

本文含有隐藏内容,请 开通VIP 后查看