作者主页:夜未央5788
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
一个简单的“在线教学平台系统”,实现基本的选课功能。
主要功能:
管理员能够实现学生基本信息的录入、修改、删除等操作,其中学生信息包括学号、姓名、性别、专业等信息;
管理员能够实现课程的录入、修改、删除等功能,其中课程信息包括课程号、课程名、课程图片、学分等;
学生能实现选课功能,每个学生可以在首页浏览课程信息,并可以进行选课操作,其中课程信息包括学分、上课地点、课程编号、授课教师、课程名等信息;
管理员可以查看学生选课信息,并可以进行添加选课学生和删除选择该课程的学生等操作;
有汇总功能,管理员首页可以查看没门课程的选课人数。
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.是否Maven项目: 是;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
6.数据库:MySql 5.7版本;
系统是一个基于SSM框架实现的项目,采用当前最流行的框架Spring-SpringMVC-MyBatis设计。
前端:HTML+BootStrap+CSS+Javascript
后端:Spring+SpringMVC+mybatis
1. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,下载所需jar包;
2. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
3. 将项目中db.properties配置文件中的数据库配置改为自己的配置
4. 配置tomcat,然后运行项目,输入localhost:8080/xxx 登录
- package cn.wxj.controller;
-
- import cn.wxj.entity.Course;
- import cn.wxj.entity.Student;
- import cn.wxj.entity.StudyInfo;
- import cn.wxj.service.IAdminService;
- import cn.wxj.service.IStudentService;
- import cn.wxj.service.IStudyService;
- import cn.wxj.util.Page;
- import cn.wxj.util.Tools;
-
- import org.apache.commons.io.FileUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.multipart.MultipartFile;
-
- import javax.servlet.ServletContext;
- import javax.servlet.http.HttpServletRequest;
-
- import java.io.File;
- import java.io.IOException;
- import java.io.UnsupportedEncodingException;
- import java.text.SimpleDateFormat;
- import java.util.Date;
-
-
- @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";
- }
- }
-
- @RequestMapping("adminDelCourse")
- public String delCourse(@RequestParam String id, HttpServletRequest req) {
- adminService.delCourse(Integer.parseInt(id));
- req.getSession().setAttribute("msg", "删除成功");
- return "redirect:/courseManage";
- }
-
- @RequestMapping(value = "/changeCourse", method = RequestMethod.GET)
- public String changeCourse(@RequestParam String id, HttpServletRequest req) {
- Course course = adminService.getCourseById(Integer.parseInt(id));
- req.getSession().setAttribute("course", course);
- return "WEB-INF/pages/course/changeClz";
- }
-
- @RequestMapping(value = "/changeCourse", method = RequestMethod.POST)
- public String changeCourse(HttpServletRequest req,
- @RequestParam("file") MultipartFile file) {
- String msg = null;
- String year_moth = df.format(new Date());
- try {
- req.setCharacterEncoding("utf-8");
-
-
- Integer id = (Integer) req.getSession().getAttribute("id");
-
- Course course = adminService.getCourseById(id);
-
- 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.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.updateCourse(course)) {
- msg = "更新成功";
- } else {
- msg = "更新失败";
- }
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- } catch (Exception e) {
- msg = "更新失败";
- e.printStackTrace();
- } finally {
- req.getSession().setAttribute("msg", msg);
- return "redirect:/courseManage";
- }
- }
-
- //功能描述:选课管理
- @RequestMapping("/chooseManage")
- public String chooseManage(@RequestParam(defaultValue="1")Integer page,
- @RequestParam(defaultValue="5")Integer rows,HttpServletRequest req,Model model) {
- Page
records = adminService.getAllStudyInfo(page,rows); - req.getSession().setAttribute("records", records.getRows());
- model.addAttribute("page", records);
- return "WEB-INF/pages/student/allChoose";
- }
-
- @RequestMapping("/delStudyInfo")
- public String delStudyInfo(HttpServletRequest req, @RequestParam String id) {
- String msg = null;
- try {
- Integer stdId = Integer.parseInt(id);
- StudyInfo info = adminService.getStudyById(stdId);
- Course c = adminService.getCourseById(info.getC_id());
- c.setSelected(c.getSelected() - 1);
- adminService.updateCourse(c);
- adminService.delStudyInfo(stdId);
- msg = "删除成功";
- } catch (Exception e) {
- msg = "删除失败";
- e.printStackTrace();
- } finally {
- req.getSession().setAttribute("msg", msg);
- return "redirect:/chooseManage";
- }
- }
-
-
- @RequestMapping("/addChoose")
- public String addChoose(HttpServletRequest req, @RequestParam String stuId, @RequestParam String clzId) {
- String msg = null;
- try {
- Integer cId = Integer.parseInt(clzId);
- Student s = adminService.getStudentById(stuId);
- Course c = adminService.getCourseById(cId);
- if (s != null && c != null) {
- if(c.getAmount()>c.getSelected()) {
- int rst = studentService.selectCource(stuId, cId);
- if (rst==0) {
- msg = "添加成功";
- } else if(rst==1){
- msg = "已经选过此课!";
- } else if(rst==2){
- msg="该课程已选满!";
- }else{
- msg="未知错误!";
- }
- }
- }else{
- msg="添加失败";
- }
- } catch (Exception e) {
- msg = "添加失败";
- e.printStackTrace();
- } finally {
- req.getSession().setAttribute("msg", msg);
- return "redirect:/chooseManage";
- }
- }
-
- }
- package cn.wxj.controller;
-
- import com.alibaba.fastjson.JSON;
-
- import cn.wxj.entity.Course;
- import cn.wxj.entity.Student;
- import cn.wxj.entity.StudyInfo;
- import cn.wxj.service.IAdminService;
- import cn.wxj.service.IClzService;
- import cn.wxj.service.IStudyService;
- import cn.wxj.util.Page;
-
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestParam;
-
- import javax.servlet.http.HttpServletRequest;
- import java.util.ArrayList;
- import java.util.List;
-
-
- @Controller
- public class DisplayController {
-
- @Autowired
- private IClzService clzService;
-
- @Autowired
- private IStudyService studyService;
-
- @Autowired
- private IAdminService adminService;
-
-
-
- //功能描述:前台首页
- @RequestMapping("/index")
- public String displayAll(HttpServletRequest req) {
-
- List
clzs = clzService.getAllClz(); - req.getSession().setAttribute("clzs", clzs);
- return "index";
- }
-
-
- //课程详情
-
- @RequestMapping("/showDetail")
- public String showDetail(@RequestParam String id, HttpServletRequest req) {
- Course course = clzService.getClzById(Integer.parseInt(id));
- req.getSession().setAttribute("course", course);
- return "WEB-INF/pages/course/detail";
- }
-
- //查看已选该门课程的所有学生列表
- @RequestMapping("/showStudent")
- public String showStudents(@RequestParam(defaultValue="1")Integer page,
- @RequestParam(defaultValue="5")Integer rows,HttpServletRequest req,Model model) {
- try {
- Integer clzId = Integer.parseInt(req.getParameter("id"));
- Page
students = studyService.getAllStuByClzId(clzId,page,rows); -
- req.getSession().setAttribute("students", students.getRows());
- model.addAttribute("page", students);
-
- } catch (NumberFormatException e) {
- e.printStackTrace();
- return "404";
- }
-
- return "WEB-INF/pages/student/stulist";
-
- }
-
-
- //功能描述:分页获取所有课程
- @RequestMapping("/showAllClasses")
- public String showAllClzs(@RequestParam(defaultValue="1")Integer page,
- @RequestParam(defaultValue="5")Integer rows,HttpServletRequest req,Model model) {
- Page
courses = clzService.getAllPageClz(page,rows); - req.getSession().setAttribute("courses", courses.getRows());
- //req.getSession().setAttribute("page", courses);
- model.addAttribute("page", courses);
- return "WEB-INF/pages/course/clzList";
- }
-
-
- //分页获取我的选课列表
- @RequestMapping("/showMyClasses")
- public String showMyClzs(@RequestParam(defaultValue="1")Integer page,
- @RequestParam(defaultValue="5")Integer rows,HttpServletRequest req,Model model) {
- String id = (String) req.getSession().getAttribute("userId");
- Page
studyInfos=null; - if(id!=null){
- studyInfos = studyService.getAllClzByStuId(id,page,rows);
- req.getSession().setAttribute("clzs", studyInfos.getRows());
- model.addAttribute("page", studyInfos);
- }else{
- req.getSession().setAttribute("clzs", null);
- }
-
- return "WEB-INF/pages/course/myClzs";
- }
-
-
- //学生管理,分页获取学生列表
- @RequestMapping("/studentManage")
- public String studentManage(@RequestParam(defaultValue="1")Integer page,
- @RequestParam(defaultValue="5")Integer rows,HttpServletRequest req,Model model){
- if(req.getSession().getAttribute("id")==null){
- return "adminLogin";
- }
- Page
students=adminService.getAllStudents(page,rows); - req.getSession().setAttribute("students", students.getRows());
- model.addAttribute("page", students);
- return "WEB-INF/pages/student/allStudents";
- }
-
-
- //后台课程管理
- @RequestMapping("/courseManage")
- public String courseManage(@RequestParam(defaultValue="1")Integer page,
- @RequestParam(defaultValue="5")Integer rows,HttpServletRequest req,Model model){
- if(req.getSession().getAttribute("id")==null){
- return "adminLogin";
- }
- Page
courses=adminService.getPageAllCourses(page,rows); - req.getSession().setAttribute("courses", courses.getRows());
- model.addAttribute("page", courses);
- return "WEB-INF/pages/course/allCourses";
- }
-
- @RequestMapping("/adminIndex")
- public String showChart(HttpServletRequest req){
- if(req.getSession().getAttribute("id")==null){
- return "adminLogin";
- }
- List
courses=adminService.getAllCourses(); - List
listX=new ArrayList(); - List
listSelected=new ArrayList(); - List
listLeft=new ArrayList(); - for(Course course:courses){
- listX.add(course.getName());
- listSelected.add(course.getSelected());
- listLeft.add(course.getAmount()-course.getSelected());
- }
-
- req.getSession().setAttribute("listX", JSON.toJSONString(listX));
- req.getSession().setAttribute("listSelected",JSON.toJSONString(listSelected));
- req.getSession().setAttribute("listLeft",JSON.toJSONString(listLeft));
- return "WEB-INF/pages/admin/admin";
- }
-
- @RequestMapping("/404")
- public String pageNotFount(){
- return "404";
- }
-
- }
如果也想学习本系统,下面领取。关注并回复:038ssm