ssm在线选课管理系统

作者主页:夜未央5788

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

文末获取源码

功能介绍

一个简单的“在线教学平台系统”,实现基本的选课功能。

主要功能:

管理员能够实现学生基本信息的录入、修改、删除等操作,其中学生信息包括学号、姓名、性别、专业等信息;

管理员能够实现课程的录入、修改、删除等功能,其中课程信息包括课程号、课程名、课程图片、学分等;

学生能实现选课功能,每个学生可以在首页浏览课程信息,并可以进行选课操作,其中课程信息包括学分、上课地点、课程编号、授课教师、课程名等信息;

管理员可以查看学生选课信息,并可以进行添加选课学生和删除选择该课程的学生等操作;

有汇总功能,管理员首页可以查看没门课程的选课人数。

软件架构

系统是一个基于SSM框架实现的项目,采用当前最流行的框架Spring-SpringMVC-MyBatis设计。

前端:HTML+BootStrap+CSS+Javascript

后端:Spring+SpringMVC+mybatis

运行截图

相关代码

管理员控制器

@Controller
public class AdminController {

    @Autowired
    private IAdminService adminService;

    @Autowired
    private IStudentService studentService;

    @Autowired
    private IStudyService studyService;
    
    public static SimpleDateFormat df = new SimpleDateFormat("yyyyMM");

    @RequestMapping(value = "/changeStudent", method = RequestMethod.GET)
    public String changeStu(@RequestParam String id, HttpServletRequest req) {
        Student student = adminService.getStudentById(id);
        req.getSession().setAttribute("student", student);
        return "WEB-INF/pages/student/changeStu";
    }

    @RequestMapping(value = "/changeStudent", method = RequestMethod.POST)
    public String changeStudent(HttpServletRequest req) {
        try {
            req.setCharacterEncoding("utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        Student student = new Student();
        student.setId(req.getParameter("id"));
        student.setName(req.getParameter("name"));
        student.setPwd(req.getParameter("pwd"));
        student.setMajor(req.getParameter("major"));
        student.setYear(req.getParameter("year"));
        student.setSex(req.getParameter("sex").charAt(0));

        String msg = null;
        if (adminService.updateStudent(student)) {
            msg = "更新成功";
        } else {
            msg = "更新失败";
        }

        req.getSession().setAttribute("msg", msg);

        return "redirect:/studentManage";
    }

    @RequestMapping(value = "addStudent", method = RequestMethod.POST)
    public String addStudent(HttpServletRequest req) {
        try {
            req.setCharacterEncoding("utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        Student student = new Student();
        student.setId(req.getParameter("id"));
        student.setName(req.getParameter("name"));
        student.setPwd(req.getParameter("pwd"));
        student.setMajor(req.getParameter("major"));
        student.setYear(req.getParameter("year"));
        student.setSex(req.getParameter("sex").charAt(0));

        String msg = null;
        if (adminService.addStudent(student)) {
            msg = "添加成功";
        } else {
            msg = "添加失败";
        }

        req.getSession().setAttribute("msg", msg);

        return "redirect:/studentManage";
    }

    @RequestMapping("delStudent")
    public String delStudent(@RequestParam String id, HttpServletRequest req) {
        adminService.delStudent(id);
        req.getSession().setAttribute("msg", "删除成功");
        return "redirect:/studentManage";
//        if (id != null) {
//            adminService.delStudent(id);
//            req.getSession().setAttribute("msg", "删除学生成功");
//        } else {
//            req.getSession().setAttribute("msg", "删除学生失败");
//        }
//
//        return "redirect:/studentManage";

    }


    //新增课程
    @RequestMapping(value = "addCourse", method = RequestMethod.POST)
    public String addCourse(HttpServletRequest req,
    		@RequestParam("file") MultipartFile file) {
        String msg = null;
        String year_moth = df.format(new Date());
        try {
            req.setCharacterEncoding("utf-8");

            Course course = new Course();
            if(!file.isEmpty()){
		    	ServletContext sc = req.getSession().getServletContext();
		        String dir = sc.getRealPath("/upload/imgurl/"+year_moth+"");    //设定文件保存的目录
		        String filename = file.getOriginalFilename();    //得到上传时的文件名
		        String tempfilename = Tools.getRndFilename()+Tools.getFileExtName(filename);          
		      			
				try {
					FileUtils.writeByteArrayToFile(new File(dir,tempfilename), file.getBytes());
				} catch (IOException e) {
					
					e.printStackTrace();
				}
				course.setImgurl("/upload/imgurl/"+year_moth+"/"+tempfilename); //设置图片所在路径
		        
		    }
            course.setName(req.getParameter("name"));
            course.setSelected(0);
            course.setAmount(Integer.parseInt(req.getParameter("amount")));
            course.setBelong(req.getParameter("belong"));
            course.setCredit(Integer.parseInt(req.getParameter("credit")));
            course.setPlace(req.getParameter("place"));
            course.setDetail(req.getParameter("detail"));
            course.setTime(req.getParameter("time"));
            if (adminService.addCourse(course)) {
                msg = "添加成功";
            } else {
                msg = "添加失败";
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (Exception e) {
            msg = "添加失败";
        } finally {
            req.getSession().setAttribute("msg", msg);
            return "redirect:/courseManage";
        }
    }

登录控制器

//系统用户登录
@Controller
public class LoginController {

    @Autowired
    private IStudentService studentService;

    @Autowired
    private IAdminService adminService;

    @RequestMapping("/login")
    public String userLogin(@RequestParam String id, @RequestParam String pwd, HttpServletRequest req) {
        Student student = null;
        if (id.length() > 0 && id.length() < 20 && pwd.length() > 0 && pwd.length() < 20) {
            student = studentService.login(id, pwd);
        }
        if (student != null) {
            req.getSession().setAttribute("user", student.getName());
            req.getSession().setAttribute("userId", student.getId());
//            req.getSession().setAttribute("msg","登录成功!欢迎您 "+student.getName()+"!");
        } else {
            req.getSession().setAttribute("msg", "登录失败!用户名或密码错误!");
        }
        return "redirect:/index";
    }

    @RequestMapping("/logout")
    public String userLogout(HttpServletRequest req) {
        req.getSession().setAttribute("user", null);
        req.getSession().setAttribute("userId", null);
        return "redirect:/index";
    }

    @RequestMapping("/changePwd")
    public String changePwd(HttpServletRequest req, @RequestParam String old,
                            @RequestParam String newpwd, @RequestParam String newagain) {

        String stuId = (String) req.getSession().getAttribute("userId");
        if (newpwd.equals(newagain) && studentService.changePwd(stuId, old, newpwd)) {
            req.getSession().setAttribute("msg", "修改成功!");
        } else {
            req.getSession().setAttribute("msg", "修改失败!");
        }
        return "redirect:/index";
    }

    @RequestMapping("/adminLogin")
    public String adminLogin(@RequestParam String username,@RequestParam String pwd,HttpServletRequest req){
        if (username.length() > 0 && username.length() < 20 && pwd.length() > 0 && pwd.length() < 20) {
            if(adminService.login(username, pwd)){
                req.getSession().setAttribute("id",username);
                return "redirect:adminIndex";
            }
        }
        return "adminLogin";
    }

}

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

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

夜未央5788

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值