基于javaweb的学生选课系统(java+javaweb+jdbc)

基于javaweb的学生选课系统(java+javaweb+jdbc)

功能介绍:
用户菜单、学生管理、教师管理、课程管理、成绩排名查询

请添加图片描述
请添加图片描述
请添加图片描述

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

            //验证码错误
            return MapControl.getInstance().error("验证码错误").getMap();
        }
        //判断用户类型
        if ("1".equals(type)) { //管理员验证登录
            User user = userService.login(userName, MD5Utils.getMD5(password)); //对密码进行加密处理,因为数据库中存储的是加密后的密码
            if (user != null) {
                session.setAttribute("user", user);
                session.setAttribute("type", 1);
                return MapControl.getInstance().success().add("data", user).getMap();
            } else {
                return MapControl.getInstance().error("用户名或密码错误").getMap();
            }
        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是否一致
    @ResponseBody
    public Map<String, Object> add(@RequestBody Student student) {
        if(StringUtils.isEmpty(student.getStuName())){
            return MapControl.getInstance().error("请填写姓名").getMap();
        }
        if(StringUtils.isEmpty(student.getJoinDate())){
            return MapControl.getInstance().error("请填写入学时间").getMap();
        }
        if(StringUtils.isEmpty(student.getStuPwd())){
            return MapControl.getInstance().error("请填写密码").getMap();
        }
        if(StringUtils.isEmpty(student.getCardNo())){
            return MapControl.getInstance().error("请填写身份证号").getMap();
        }
                return MapControl.getInstance().error("用户名或密码错误").getMap();
            }
        }
        if ("2".equals(type)) { //老师验证登录
            Teacher teacher = teacherService.login(userName, MD5Utils.getMD5(password));
            if (teacher != null) {
                session.setAttribute("user", teacher);
                session.setAttribute("type", "2");
                return MapControl.getInstance().success().add("data", teacher).getMap();
            } else {
                return MapControl.getInstance().error("用户名或密码错误").getMap();
            }
        }
        if ("3".equals(type)) { //学生验证登录
            Student student = studentService.login(userName, MD5Utils.getMD5(password));
            if (student != null) {
                session.setAttribute("user", student);
                session.setAttribute("type", "3");
                return MapControl.getInstance().success().add("data", student).getMap();
            } else {
                return MapControl.getInstance().error("用户名或密码错误").getMap();
            }
        }
     * @param student
     * @return
     */
    @PostMapping("/edit")
    @ResponseBody
    public Map<String, Object> edit(@RequestBody Student student) {
        if(StringUtils.isEmpty(student.getStuName())){
            return MapControl.getInstance().error("请填写姓名").getMap();
        }
        if(StringUtils.isEmpty(student.getJoinDate())){
            return MapControl.getInstance().error("请填写入学时间").getMap();
        }
        if(StringUtils.isEmpty(student.getCardNo())){
            return MapControl.getInstance().error("请填写身份证号").getMap();
        }
        if(StringUtils.isEmpty(student.getPhone())){
            return MapControl.getInstance().error("请填写手机号码").getMap();
        }
        int result = studentService.saveU(student);
    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);
登录控制层:
@Controller
public class LoginController {
    @Autowired
    private UserService userService;
    @Autowired
    private TeacherService teacherService;
    @Autowired
    private StudentService studentService;
    //跳转登录页面
    @GetMapping("/login")
    public String login() {
        return "login";
    }
    //登录操作
    @PostMapping("/login")
    @ResponseBody
    public Map<String, Object> login(String userName, String password, String captcha, String type, HttpSession session) {
        //判断用户名、密码、用户类型、验证码是否为空
        if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(password) || StringUtils.isEmpty(captcha) || StringUtils.isEmpty(type)) {
            return MapControl.getInstance().error("用户名或密码不能为空").getMap();
        }
        return MapControl.getInstance().getMap();
    }
}
学生管理控制层:
@Controller
@RequestMapping("/student")
public class StudentController {
    private static final String LIST = "student/list";
    @Autowired
    private StudentService studentService;
    @Autowired
    private SubjectService subjectService;
    @Autowired
    private ClazzService clazzService;
    //跳转添加页面
    @GetMapping("/add")
    public String add(ModelMap modelMap) {
        //查询所有的专业,存储到request域
        List<Subject> subjects = subjectService.query(null);
        modelMap.addAttribute("subjects", subjects);
        return MapControl.getInstance().success().page(list, count).getMap();
    }
    //跳转列表页面
    @GetMapping("/list")
    public String list() {
        return "student/list";
    }
    //跳转查询学生页面
    @GetMapping("/teacher_student")
    public String teacher_student(ModelMap modelMap, HttpSession session) {
        if ("2".equals(type)) { //老师验证登录
            Teacher teacher = teacherService.login(userName, MD5Utils.getMD5(password));
            if (teacher != null) {
                session.setAttribute("user", teacher);
                session.setAttribute("type", "2");
                return MapControl.getInstance().success().add("data", teacher).getMap();
            } else {
                return MapControl.getInstance().error("用户名或密码错误").getMap();
            }
        }
        if ("3".equals(type)) { //学生验证登录
            Student student = studentService.login(userName, MD5Utils.getMD5(password));
            if (student != null) {
                session.setAttribute("user", student);
                session.setAttribute("type", "3");
                return MapControl.getInstance().success().add("data", student).getMap();
            } else {
                return MapControl.getInstance().error("用户名或密码错误").getMap();
            }
        }
        return MapControl.getInstance().getMap();
    }
}
    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";
        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();
    }
    /**
     * 学生修改操作
     * @param student
    }
    /**
     * 学生添加操作
     * @param student
     * @return
     */
    @PostMapping("/add")
    @ResponseBody
    public Map<String, Object> add(@RequestBody Student student) {
        if(StringUtils.isEmpty(student.getStuName())){
            return MapControl.getInstance().error("请填写姓名").getMap();
        }
        if(StringUtils.isEmpty(student.getJoinDate())){
            return MapControl.getInstance().error("请填写入学时间").getMap();
        }
        if(StringUtils.isEmpty(student.getStuPwd())){
            return MapControl.getInstance().error("请填写密码").getMap();
        }
        if(StringUtils.isEmpty(student.getCardNo())){
            return MapControl.getInstance().error("请填写身份证号").getMap();
                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 "student/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);
            return MapControl.getInstance().error().getMap();
        }
        return MapControl.getInstance().success().getMap();
    }
    /**
     * 学生修改操作
     * @param student
     * @return
     */
    @PostMapping("/edit")
        int result = userService.delete(ids);
        if (result <= 0) {
            return MapControl.getInstance().error().getMap();
        }
        return MapControl.getInstance().success().getMap();
    }
    /**
     * 编辑用户信息操作
     * @param user
     * @return
        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();
        }
        //查询总记录条数
        Integer count = studentService.count(student);
        return MapControl.getInstance().success().page(list, count).getMap();
    }
    //跳转列表页面
    @GetMapping("/list")
    public String list() {
        return "student/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);
    }
    //查询所有
    @PostMapping("/query")
    @ResponseBody
    public Map<String, Object> query(@RequestBody User user) {
        List<User> list = userService.query(user);
        Integer count = userService.count(user);
        return MapControl.getInstance().success().page(list, count).getMap();
    }
    //跳转列表页面
    @GetMapping("/list")
    public String list() {
                }
            });
            clazzes.forEach(clazz -> {
                //判断学生表的clazzId和班级表的id是否一致
                if (clazz.getId() == entity.getClazzId()) {
                    entity.setClazz(clazz);
                }
            });
        });
        return MapControl.getInstance().success().add("data", students).getMap();
    }
}
用户管理操作:
/**
 * 用户管理操作
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    /**
     * 学生添加操作
     * @param student
     * @return
     */
    @PostMapping("/add")
    @ResponseBody
    public Map<String, Object> add(@RequestBody Student student) {
        if(StringUtils.isEmpty(student.getStuName())){
            return MapControl.getInstance().error("请填写姓名").getMap();
        }
        if(StringUtils.isEmpty(student.getJoinDate())){
            return MapControl.getInstance().error("请填写入学时间").getMap();
        }
        if(StringUtils.isEmpty(student.getStuPwd())){
            return MapControl.getInstance().error("请填写密码").getMap();
        }
        if(StringUtils.isEmpty(student.getCardNo())){
            return MapControl.getInstance().error("请填写身份证号").getMap();
        }
        if(StringUtils.isEmpty(student.getPhone())){
            return MapControl.getInstance().error("请填写手机号码").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();
    }
        if (result <= 0) {
            return MapControl.getInstance().error().getMap();
        }
        return MapControl.getInstance().success().getMap();
    }
    /**
     * 根据id删除
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    @ResponseBody
    public Map<String, Object> delete(@PathVariable("id") Integer id) {
        int result = userService.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 = userService.delete(ids);
     * @return
     */
    @PostMapping("/edit")
    @ResponseBody
    public Map<String, Object> edit(@RequestBody User user) {
        if(StringUtils.isEmpty(user.getUserName())){
            return MapControl.getInstance().error("请填写用户名").getMap();
        }
        if(StringUtils.isEmpty(user.getName())){
            return MapControl.getInstance().error("请填写名称").getMap();
        }
        if(StringUtils.isEmpty(user.getUserPwd())){
            return MapControl.getInstance().error("请填写密码").getMap();
        }
        int result = userService.update(user);
        if (result <= 0) {
        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);
                }
        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();
    }
}
            if (user != null) {
                session.setAttribute("user", user);
                session.setAttribute("type", 1);
                return MapControl.getInstance().success().add("data", user).getMap();
            } else {
                return MapControl.getInstance().error("用户名或密码错误").getMap();
            }
        }
        if ("2".equals(type)) { //老师验证登录
            Teacher teacher = teacherService.login(userName, MD5Utils.getMD5(password));
            if (teacher != null) {
                session.setAttribute("user", teacher);
                session.setAttribute("type", "2");
                return MapControl.getInstance().success().add("data", teacher).getMap();
     * @param student
     * @return
     */
    @PostMapping("/edit")
    @ResponseBody
    public Map<String, Object> edit(@RequestBody Student student) {
        if(StringUtils.isEmpty(student.getStuName())){
            return MapControl.getInstance().error("请填写姓名").getMap();
        }
        if(StringUtils.isEmpty(student.getJoinDate())){
            return MapControl.getInstance().error("请填写入学时间").getMap();
        }
        if(StringUtils.isEmpty(student.getCardNo())){
            return MapControl.getInstance().error("请填写身份证号").getMap();
        }
        if(StringUtils.isEmpty(student.getPhone())){
            return MapControl.getInstance().error("请填写手机号码").getMap();
        }
        int result = studentService.saveU(student);
        if (result <= 0) {
            return MapControl.getInstance().error().getMap();
        }

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值