• Java项目:ssm在线选课管理系统


    作者主页:夜未央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 登录

    运行截图

    相关代码 

    AdminController

    1. package cn.wxj.controller;
    2. import cn.wxj.entity.Course;
    3. import cn.wxj.entity.Student;
    4. import cn.wxj.entity.StudyInfo;
    5. import cn.wxj.service.IAdminService;
    6. import cn.wxj.service.IStudentService;
    7. import cn.wxj.service.IStudyService;
    8. import cn.wxj.util.Page;
    9. import cn.wxj.util.Tools;
    10. import org.apache.commons.io.FileUtils;
    11. import org.springframework.beans.factory.annotation.Autowired;
    12. import org.springframework.stereotype.Controller;
    13. import org.springframework.ui.Model;
    14. import org.springframework.web.bind.annotation.RequestMapping;
    15. import org.springframework.web.bind.annotation.RequestMethod;
    16. import org.springframework.web.bind.annotation.RequestParam;
    17. import org.springframework.web.multipart.MultipartFile;
    18. import javax.servlet.ServletContext;
    19. import javax.servlet.http.HttpServletRequest;
    20. import java.io.File;
    21. import java.io.IOException;
    22. import java.io.UnsupportedEncodingException;
    23. import java.text.SimpleDateFormat;
    24. import java.util.Date;
    25. @Controller
    26. public class AdminController {
    27. @Autowired
    28. private IAdminService adminService;
    29. @Autowired
    30. private IStudentService studentService;
    31. @Autowired
    32. private IStudyService studyService;
    33. public static SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
    34. @RequestMapping(value = "/changeStudent", method = RequestMethod.GET)
    35. public String changeStu(@RequestParam String id, HttpServletRequest req) {
    36. Student student = adminService.getStudentById(id);
    37. req.getSession().setAttribute("student", student);
    38. return "WEB-INF/pages/student/changeStu";
    39. }
    40. @RequestMapping(value = "/changeStudent", method = RequestMethod.POST)
    41. public String changeStudent(HttpServletRequest req) {
    42. try {
    43. req.setCharacterEncoding("utf-8");
    44. } catch (UnsupportedEncodingException e) {
    45. e.printStackTrace();
    46. }
    47. Student student = new Student();
    48. student.setId(req.getParameter("id"));
    49. student.setName(req.getParameter("name"));
    50. student.setPwd(req.getParameter("pwd"));
    51. student.setMajor(req.getParameter("major"));
    52. student.setYear(req.getParameter("year"));
    53. student.setSex(req.getParameter("sex").charAt(0));
    54. String msg = null;
    55. if (adminService.updateStudent(student)) {
    56. msg = "更新成功";
    57. } else {
    58. msg = "更新失败";
    59. }
    60. req.getSession().setAttribute("msg", msg);
    61. return "redirect:/studentManage";
    62. }
    63. @RequestMapping(value = "addStudent", method = RequestMethod.POST)
    64. public String addStudent(HttpServletRequest req) {
    65. try {
    66. req.setCharacterEncoding("utf-8");
    67. } catch (UnsupportedEncodingException e) {
    68. e.printStackTrace();
    69. }
    70. Student student = new Student();
    71. student.setId(req.getParameter("id"));
    72. student.setName(req.getParameter("name"));
    73. student.setPwd(req.getParameter("pwd"));
    74. student.setMajor(req.getParameter("major"));
    75. student.setYear(req.getParameter("year"));
    76. student.setSex(req.getParameter("sex").charAt(0));
    77. String msg = null;
    78. if (adminService.addStudent(student)) {
    79. msg = "添加成功";
    80. } else {
    81. msg = "添加失败";
    82. }
    83. req.getSession().setAttribute("msg", msg);
    84. return "redirect:/studentManage";
    85. }
    86. @RequestMapping("delStudent")
    87. public String delStudent(@RequestParam String id, HttpServletRequest req) {
    88. adminService.delStudent(id);
    89. req.getSession().setAttribute("msg", "删除成功");
    90. return "redirect:/studentManage";
    91. // if (id != null) {
    92. // adminService.delStudent(id);
    93. // req.getSession().setAttribute("msg", "删除学生成功");
    94. // } else {
    95. // req.getSession().setAttribute("msg", "删除学生失败");
    96. // }
    97. //
    98. // return "redirect:/studentManage";
    99. }
    100. //新增课程
    101. @RequestMapping(value = "addCourse", method = RequestMethod.POST)
    102. public String addCourse(HttpServletRequest req,
    103. @RequestParam("file") MultipartFile file) {
    104. String msg = null;
    105. String year_moth = df.format(new Date());
    106. try {
    107. req.setCharacterEncoding("utf-8");
    108. Course course = new Course();
    109. if(!file.isEmpty()){
    110. ServletContext sc = req.getSession().getServletContext();
    111. String dir = sc.getRealPath("/upload/imgurl/"+year_moth+""); //设定文件保存的目录
    112. String filename = file.getOriginalFilename(); //得到上传时的文件名
    113. String tempfilename = Tools.getRndFilename()+Tools.getFileExtName(filename);
    114. try {
    115. FileUtils.writeByteArrayToFile(new File(dir,tempfilename), file.getBytes());
    116. } catch (IOException e) {
    117. e.printStackTrace();
    118. }
    119. course.setImgurl("/upload/imgurl/"+year_moth+"/"+tempfilename); //设置图片所在路径
    120. }
    121. course.setName(req.getParameter("name"));
    122. course.setSelected(0);
    123. course.setAmount(Integer.parseInt(req.getParameter("amount")));
    124. course.setBelong(req.getParameter("belong"));
    125. course.setCredit(Integer.parseInt(req.getParameter("credit")));
    126. course.setPlace(req.getParameter("place"));
    127. course.setDetail(req.getParameter("detail"));
    128. course.setTime(req.getParameter("time"));
    129. if (adminService.addCourse(course)) {
    130. msg = "添加成功";
    131. } else {
    132. msg = "添加失败";
    133. }
    134. } catch (UnsupportedEncodingException e) {
    135. e.printStackTrace();
    136. } catch (Exception e) {
    137. msg = "添加失败";
    138. } finally {
    139. req.getSession().setAttribute("msg", msg);
    140. return "redirect:/courseManage";
    141. }
    142. }
    143. @RequestMapping("adminDelCourse")
    144. public String delCourse(@RequestParam String id, HttpServletRequest req) {
    145. adminService.delCourse(Integer.parseInt(id));
    146. req.getSession().setAttribute("msg", "删除成功");
    147. return "redirect:/courseManage";
    148. }
    149. @RequestMapping(value = "/changeCourse", method = RequestMethod.GET)
    150. public String changeCourse(@RequestParam String id, HttpServletRequest req) {
    151. Course course = adminService.getCourseById(Integer.parseInt(id));
    152. req.getSession().setAttribute("course", course);
    153. return "WEB-INF/pages/course/changeClz";
    154. }
    155. @RequestMapping(value = "/changeCourse", method = RequestMethod.POST)
    156. public String changeCourse(HttpServletRequest req,
    157. @RequestParam("file") MultipartFile file) {
    158. String msg = null;
    159. String year_moth = df.format(new Date());
    160. try {
    161. req.setCharacterEncoding("utf-8");
    162. Integer id = (Integer) req.getSession().getAttribute("id");
    163. Course course = adminService.getCourseById(id);
    164. if(!file.isEmpty()){
    165. ServletContext sc = req.getSession().getServletContext();
    166. String dir = sc.getRealPath("/upload/imgurl/"+year_moth+""); //设定文件保存的目录
    167. String filename = file.getOriginalFilename(); //得到上传时的文件名
    168. String tempfilename = Tools.getRndFilename()+Tools.getFileExtName(filename);
    169. try {
    170. FileUtils.writeByteArrayToFile(new File(dir,tempfilename), file.getBytes());
    171. } catch (IOException e) {
    172. e.printStackTrace();
    173. }
    174. course.setImgurl("/upload/imgurl/"+year_moth+"/"+tempfilename); //设置图片所在路径
    175. }
    176. course.setName(req.getParameter("name"));
    177. course.setAmount(Integer.parseInt(req.getParameter("amount")));
    178. course.setBelong(req.getParameter("belong"));
    179. course.setCredit(Integer.parseInt(req.getParameter("credit")));
    180. course.setPlace(req.getParameter("place"));
    181. course.setDetail(req.getParameter("detail"));
    182. course.setTime(req.getParameter("time"));
    183. if (adminService.updateCourse(course)) {
    184. msg = "更新成功";
    185. } else {
    186. msg = "更新失败";
    187. }
    188. } catch (UnsupportedEncodingException e) {
    189. e.printStackTrace();
    190. } catch (Exception e) {
    191. msg = "更新失败";
    192. e.printStackTrace();
    193. } finally {
    194. req.getSession().setAttribute("msg", msg);
    195. return "redirect:/courseManage";
    196. }
    197. }
    198. //功能描述:选课管理
    199. @RequestMapping("/chooseManage")
    200. public String chooseManage(@RequestParam(defaultValue="1")Integer page,
    201. @RequestParam(defaultValue="5")Integer rows,HttpServletRequest req,Model model) {
    202. Page records = adminService.getAllStudyInfo(page,rows);
    203. req.getSession().setAttribute("records", records.getRows());
    204. model.addAttribute("page", records);
    205. return "WEB-INF/pages/student/allChoose";
    206. }
    207. @RequestMapping("/delStudyInfo")
    208. public String delStudyInfo(HttpServletRequest req, @RequestParam String id) {
    209. String msg = null;
    210. try {
    211. Integer stdId = Integer.parseInt(id);
    212. StudyInfo info = adminService.getStudyById(stdId);
    213. Course c = adminService.getCourseById(info.getC_id());
    214. c.setSelected(c.getSelected() - 1);
    215. adminService.updateCourse(c);
    216. adminService.delStudyInfo(stdId);
    217. msg = "删除成功";
    218. } catch (Exception e) {
    219. msg = "删除失败";
    220. e.printStackTrace();
    221. } finally {
    222. req.getSession().setAttribute("msg", msg);
    223. return "redirect:/chooseManage";
    224. }
    225. }
    226. @RequestMapping("/addChoose")
    227. public String addChoose(HttpServletRequest req, @RequestParam String stuId, @RequestParam String clzId) {
    228. String msg = null;
    229. try {
    230. Integer cId = Integer.parseInt(clzId);
    231. Student s = adminService.getStudentById(stuId);
    232. Course c = adminService.getCourseById(cId);
    233. if (s != null && c != null) {
    234. if(c.getAmount()>c.getSelected()) {
    235. int rst = studentService.selectCource(stuId, cId);
    236. if (rst==0) {
    237. msg = "添加成功";
    238. } else if(rst==1){
    239. msg = "已经选过此课!";
    240. } else if(rst==2){
    241. msg="该课程已选满!";
    242. }else{
    243. msg="未知错误!";
    244. }
    245. }
    246. }else{
    247. msg="添加失败";
    248. }
    249. } catch (Exception e) {
    250. msg = "添加失败";
    251. e.printStackTrace();
    252. } finally {
    253. req.getSession().setAttribute("msg", msg);
    254. return "redirect:/chooseManage";
    255. }
    256. }
    257. }

    DisplayController

    1. package cn.wxj.controller;
    2. import com.alibaba.fastjson.JSON;
    3. import cn.wxj.entity.Course;
    4. import cn.wxj.entity.Student;
    5. import cn.wxj.entity.StudyInfo;
    6. import cn.wxj.service.IAdminService;
    7. import cn.wxj.service.IClzService;
    8. import cn.wxj.service.IStudyService;
    9. import cn.wxj.util.Page;
    10. import org.springframework.beans.factory.annotation.Autowired;
    11. import org.springframework.stereotype.Controller;
    12. import org.springframework.ui.Model;
    13. import org.springframework.web.bind.annotation.RequestMapping;
    14. import org.springframework.web.bind.annotation.RequestParam;
    15. import javax.servlet.http.HttpServletRequest;
    16. import java.util.ArrayList;
    17. import java.util.List;
    18. @Controller
    19. public class DisplayController {
    20. @Autowired
    21. private IClzService clzService;
    22. @Autowired
    23. private IStudyService studyService;
    24. @Autowired
    25. private IAdminService adminService;
    26. //功能描述:前台首页
    27. @RequestMapping("/index")
    28. public String displayAll(HttpServletRequest req) {
    29. List clzs = clzService.getAllClz();
    30. req.getSession().setAttribute("clzs", clzs);
    31. return "index";
    32. }
    33. //课程详情
    34. @RequestMapping("/showDetail")
    35. public String showDetail(@RequestParam String id, HttpServletRequest req) {
    36. Course course = clzService.getClzById(Integer.parseInt(id));
    37. req.getSession().setAttribute("course", course);
    38. return "WEB-INF/pages/course/detail";
    39. }
    40. //查看已选该门课程的所有学生列表
    41. @RequestMapping("/showStudent")
    42. public String showStudents(@RequestParam(defaultValue="1")Integer page,
    43. @RequestParam(defaultValue="5")Integer rows,HttpServletRequest req,Model model) {
    44. try {
    45. Integer clzId = Integer.parseInt(req.getParameter("id"));
    46. Page students = studyService.getAllStuByClzId(clzId,page,rows);
    47. req.getSession().setAttribute("students", students.getRows());
    48. model.addAttribute("page", students);
    49. } catch (NumberFormatException e) {
    50. e.printStackTrace();
    51. return "404";
    52. }
    53. return "WEB-INF/pages/student/stulist";
    54. }
    55. //功能描述:分页获取所有课程
    56. @RequestMapping("/showAllClasses")
    57. public String showAllClzs(@RequestParam(defaultValue="1")Integer page,
    58. @RequestParam(defaultValue="5")Integer rows,HttpServletRequest req,Model model) {
    59. Page courses = clzService.getAllPageClz(page,rows);
    60. req.getSession().setAttribute("courses", courses.getRows());
    61. //req.getSession().setAttribute("page", courses);
    62. model.addAttribute("page", courses);
    63. return "WEB-INF/pages/course/clzList";
    64. }
    65. //分页获取我的选课列表
    66. @RequestMapping("/showMyClasses")
    67. public String showMyClzs(@RequestParam(defaultValue="1")Integer page,
    68. @RequestParam(defaultValue="5")Integer rows,HttpServletRequest req,Model model) {
    69. String id = (String) req.getSession().getAttribute("userId");
    70. Page studyInfos=null;
    71. if(id!=null){
    72. studyInfos = studyService.getAllClzByStuId(id,page,rows);
    73. req.getSession().setAttribute("clzs", studyInfos.getRows());
    74. model.addAttribute("page", studyInfos);
    75. }else{
    76. req.getSession().setAttribute("clzs", null);
    77. }
    78. return "WEB-INF/pages/course/myClzs";
    79. }
    80. //学生管理,分页获取学生列表
    81. @RequestMapping("/studentManage")
    82. public String studentManage(@RequestParam(defaultValue="1")Integer page,
    83. @RequestParam(defaultValue="5")Integer rows,HttpServletRequest req,Model model){
    84. if(req.getSession().getAttribute("id")==null){
    85. return "adminLogin";
    86. }
    87. Page students=adminService.getAllStudents(page,rows);
    88. req.getSession().setAttribute("students", students.getRows());
    89. model.addAttribute("page", students);
    90. return "WEB-INF/pages/student/allStudents";
    91. }
    92. //后台课程管理
    93. @RequestMapping("/courseManage")
    94. public String courseManage(@RequestParam(defaultValue="1")Integer page,
    95. @RequestParam(defaultValue="5")Integer rows,HttpServletRequest req,Model model){
    96. if(req.getSession().getAttribute("id")==null){
    97. return "adminLogin";
    98. }
    99. Page courses=adminService.getPageAllCourses(page,rows);
    100. req.getSession().setAttribute("courses", courses.getRows());
    101. model.addAttribute("page", courses);
    102. return "WEB-INF/pages/course/allCourses";
    103. }
    104. @RequestMapping("/adminIndex")
    105. public String showChart(HttpServletRequest req){
    106. if(req.getSession().getAttribute("id")==null){
    107. return "adminLogin";
    108. }
    109. List courses=adminService.getAllCourses();
    110. List listX=new ArrayList();
    111. List listSelected=new ArrayList();
    112. List listLeft=new ArrayList();
    113. for(Course course:courses){
    114. listX.add(course.getName());
    115. listSelected.add(course.getSelected());
    116. listLeft.add(course.getAmount()-course.getSelected());
    117. }
    118. req.getSession().setAttribute("listX", JSON.toJSONString(listX));
    119. req.getSession().setAttribute("listSelected",JSON.toJSONString(listSelected));
    120. req.getSession().setAttribute("listLeft",JSON.toJSONString(listLeft));
    121. return "WEB-INF/pages/admin/admin";
    122. }
    123. @RequestMapping("/404")
    124. public String pageNotFount(){
    125. return "404";
    126. }
    127. }

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

  • 相关阅读:
    编译工具链 之二 详解 ELF 格式及标准、UNIX 发展、ABI
    第9章 K8s进阶篇-持久化存储入门
    如果再写for循环,我就锤自己了
    CentOS 8最小安装,VM使用这个内存占用小很多
    web前端期末大作业:基于HTML+CSS+JS外卖服务平台10页 带购物车 (web课程设计与实现)
    特殊品种的二次开户验资金额
    React组件进阶
    scp报错not a regular file - 猫头虎博主为您深入解析
    P1220 关路灯 ( 区间dp
    js生成图片的多边形科技感效果
  • 原文地址:https://blog.csdn.net/hanyunlong1989/article/details/126754424