学生管理系统--java+mysql
发布人:shili8
发布时间:2024-12-24 07:20
阅读次数:0
**学生管理系统**
**概述**
本系统是一个简单的学生管理系统,主要功能包括学生信息管理、课程管理、成绩管理等。系统使用Java语言编写,并与MySQL数据库进行交互。
**系统结构**
系统分为以下几个模块:
1. **学生管理模块**
* 添加学生* 删除学生* 修改学生信息* 查询学生信息2. **课程管理模块**
* 添加课程* 删除课程* 修改课程信息* 查询课程信息3. **成绩管理模块**
* 添加成绩* 删除成绩* 修改成绩* 查询成绩**系统设计**
###1.学生管理模块#### 添加学生
java// Student.javapublic class Student { private int id; private String name; private String sex; public Student(int id, String name, String sex) { this.id = id; this.name = name; this.sex = sex; } // getter和setter方法} // AddStudentServlet.java@WebServlet("/addStudent") public class AddStudentServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String name = request.getParameter("name"); String sex = request.getParameter("sex"); Student student = new Student(1, name, sex); // 将学生信息插入数据库 StudentDAO.addStudent(student); response.sendRedirect("/studentList"); } }
#### 删除学生
java// DeleteStudentServlet.java@WebServlet("/deleteStudent") public class DeleteStudentServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int id = Integer.parseInt(request.getParameter("id")); // 从数据库中删除学生信息 StudentDAO.deleteStudent(id); response.sendRedirect("/studentList"); } }
#### 修改学生信息
java// UpdateStudentServlet.java@WebServlet("/updateStudent") public class UpdateStudentServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int id = Integer.parseInt(request.getParameter("id")); String name = request.getParameter("name"); String sex = request.getParameter("sex"); Student student = new Student(id, name, sex); // 更新学生信息到数据库 StudentDAO.updateStudent(student); response.sendRedirect("/studentList"); } }
#### 查询学生信息
java// QueryStudentServlet.java@WebServlet("/queryStudent") public class QueryStudentServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int id = Integer.parseInt(request.getParameter("id")); Student student = StudentDAO.queryStudent(id); // 将学生信息传递给JSP页面 request.setAttribute("student", student); RequestDispatcher dispatcher = request.getRequestDispatcher("/studentInfo.jsp"); dispatcher.forward(request, response); } }
###2.课程管理模块#### 添加课程
java// Course.javapublic class Course { private int id; private String name; public Course(int id, String name) { this.id = id; this.name = name; } // getter和setter方法} // AddCourseServlet.java@WebServlet("/addCourse") public class AddCourseServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String name = request.getParameter("name"); Course course = new Course(1, name); // 将课程信息插入数据库 CourseDAO.addCourse(course); response.sendRedirect("/courseList"); } }
#### 删除课程
java// DeleteCourseServlet.java@WebServlet("/deleteCourse") public class DeleteCourseServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int id = Integer.parseInt(request.getParameter("id")); // 从数据库中删除课程信息 CourseDAO.deleteCourse(id); response.sendRedirect("/courseList"); } }
#### 修改课程信息
java// UpdateCourseServlet.java@WebServlet("/updateCourse") public class UpdateCourseServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int id = Integer.parseInt(request.getParameter("id")); String name = request.getParameter("name"); Course course = new Course(id, name); // 更新课程信息到数据库 CourseDAO.updateCourse(course); response.sendRedirect("/courseList"); } }
#### 查询课程信息
java// QueryCourseServlet.java@WebServlet("/queryCourse") public class QueryCourseServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int id = Integer.parseInt(request.getParameter("id")); Course course = CourseDAO.queryCourse(id); // 将课程信息传递给JSP页面 request.setAttribute("course", course); RequestDispatcher dispatcher = request.getRequestDispatcher("/courseInfo.jsp"); dispatcher.forward(request, response); } }
###3.成绩管理模块#### 添加成绩
java// Score.javapublic class Score { private int id; private int studentId; private int courseId; private double score; public Score(int id, int studentId, int courseId, double score) { this.id = id; this.studentId = studentId; this.courseId = courseId; this.score = score; } // getter和setter方法} // AddScoreServlet.java@WebServlet("/addScore") public class AddScoreServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int studentId = Integer.parseInt(request.getParameter("studentId")); int courseId = Integer.parseInt(request.getParameter("courseId")); double score = Double.parseDouble(request.getParameter("score")); Score scoreObj = new Score(1, studentId, courseId, score); // 将成绩信息插入数据库 ScoreDAO.addScore(scoreObj); response.sendRedirect("/scoreList"); } }
#### 删除成绩
java// DeleteScoreServlet.java@WebServlet("/deleteScore") public class DeleteScoreServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int id = Integer.parseInt(request.getParameter("id")); // 从数据库中删除成绩信息 ScoreDAO.deleteScore(id); response.sendRedirect("/scoreList"); } }
#### 修改成绩
java// UpdateScoreServlet.java@WebServlet("/updateScore") public class UpdateScoreServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int id = Integer.parseInt(request.getParameter("id")); double score = Double.parseDouble(request.getParameter("score")); Score scoreObj = new Score(id,1,1, score); // 更新成绩信息到数据库 ScoreDAO.updateScore(scoreObj); response.sendRedirect("/scoreList"); } }
#### 查询成绩
java// QueryScoreServlet.java@WebServlet("/queryScore") public class QueryScoreServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int id = Integer.parseInt(request.getParameter("id")); Score scoreObj = ScoreDAO.queryScore(id); // 将成绩信息传递给JSP页面 request.setAttribute("score", scoreObj); RequestDispatcher dispatcher = request.getRequestDispatcher("/scoreInfo.jsp"); dispatcher.forward(request, response); } }
**数据库设计**
学生管理系统的数据库设计如下:
| 表名 | 字段 |
| --- | --- |
| student | id、name、sex |
| course | id、name |
| score | id、studentId、courseId、score |
**总结**
本文介绍了一个简单的学生管理系统,包括学生信息管理、课程管理和成绩管理等功能。系统使用Java语言编写,并与MySQL数据库进行交互。学生管理模块包括添加学生、删除学生、修改学生信息和查询学生信息等功能;课程管理模块包括添加课程、删除课程、修改课程信息和查询课程信息等功能;成绩管理模块包括添加成绩、删除成绩、修改成绩和查询成绩等功能。系统的数据库设计包括三个表:student、course和score。
**参考**
本文中的代码示例和数据库设计参考了以下资源:
* Java Servlet API* MySQL数据库* JSP页面以上是关于学生管理系统的详细介绍,希望对您有所帮助!