1、 项目概述
1.1 项目主要内容
1.简述本项目实现的主要内容和目标
(1)实现一个简单的学生信息管理的程序StudentInfo。
(2)教学管理人员能够使用StudentInfo程序对学生基本信息、课程信息进行管理,包括数据的添加、修改、删除和浏览;
(3)能够对学生选课进行管理,包括添加学生选课信息、录入成绩;
(4)能够使用查询功能,快速查看到指定学生或指定课程的基本信息以及所指定学生的选课信息;
(5)要注意添加学生基本信息、课程信息相关数据时,学号和课程号不能重复;还有在添加学生选课信息时,要求该学生和课程必须是存在的,而且不能添加重复的选课信息。
(6)提供友好的交互界面,可以方便用户进行功能选择,实现信息的管理和查询,并可清晰地显示相关信息。
2.使用的开发平台:IDEA.Java Swing
1.2 项目需求分析
管理员能够使用该程序对学生基本信息、课程信息、成绩信息进行管理,包括数据的增加、修改、删除和查询。
增加功能:增加学生基本信息、课程信息、成绩信息。增加时学生学号和课程号不可重复,且在选课信息部分增加的学生和课程必须存在;
修改功能:修改学生和课程基本信息以及选课信息。注意点和增加部分一样;
删除功能:可以删除不需要的信息。若被删除的信息在其他表中被使用,则应先停止此信息的使用,再允许删除。
查询功能:快速查看到指定学生的基本和选课信息或指定课程的基本信息;考虑到便捷性,最好实现输入不完全的信息即可查询的功能。
提供友好的交互界面,可以方便用户进行功能选择,实现信息的管理和查询,并可清晰地显示相关信息。
2、 项目设计
2.1 项目目标
根据上面的需求分析,学生成绩管理系统要达到的目标:
(1)教学管理人员能够使用StudentInfo程序对学生基本信息、课程信息进行管理,包括数据的添加、修改、删除和浏览;
(2)能够对学生选课进行管理,包括添加学生选课信息、录入成绩;
(3)能够使用查询功能,快速查看到指定学生或指定课程的基本信息以及所指定学生的选课信息;
(4)要注意添加学生基本信息、课程信息相关数据时,学号和课程号不能重复;还有在添加学生选课信息时,要求该学生和课程必须是存在的,而且不能添加重复的选课信息。
(5)提供友好的交互界面,可以方便用户进行功能选择,实现信息的管理和查询,并可清晰地显示相关信息。
2.2 构建开发环境
【1】系统开发平台:Eclipse,Java,Mysql
【2】系统开发语言:Java、数据库语言
【3】运行平台:IDEA.JAVA.Swing
2.3 系统功能结构
学生信息管理系统在数据库建立三个表,分别为:教师表、学生表、课程表,对于每个表格,都可以对上面的信息进行增删改查等操作。
3、功能分析
学生管理系统所需要达成如下功能:
4、详细设计
4.1 Package dao
【1】 模块概述
CourseDao操作实体类、ScoreDao操作实体类、StudentDao操作实体类、UserDao操作实体类。
【2】 代码实现
CourseDao操作实体类:
package com.score.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import com.score.model.Course;
import com.score.utils.DBUtils;
/**
* CourseDao操作实体类
*/
public class CourseDao {
/**
* 添加Course
*/
public void insert(Course course){
Connection conn = null;
PreparedStatement psmt = null;
try {
conn = DBUtils.getConnection();
String sql = “insert into course(cname,tname) values(?,?)”;
psmt = conn.prepareStatement(sql);
psmt.setString(1, course.getCname());
psmt.setString(2, course.getTname());
psmt.executeUpdate();
DBUtils.close(conn, psmt);
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
*修改Course
*/
public void update(Course course){
Connection conn = null;
PreparedStatement psmt = null;
try {
conn = DBUtils.getConnection();
String sql = “update course set cname=?,tname=? where id = ?”;
psmt = conn.prepareStatement(sql);
psmt.setString(1, course.getCname());
psmt.setString(2, course.getTname());
psmt.setInt(3, course.getId());
psmt.executeUpdate();
DBUtils.close(conn, psmt);
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* 删除Course
*/
public void delete(int id){
Connection conn = null;
PreparedStatement psmt = null;
try {
conn = DBUtils.getConnection();
String sql = “delete from course where id = ?”;
psmt = conn.prepareStatement(sql);
psmt.setInt(1, id);
psmt.executeUpdate();
DBUtils.close(conn, psmt);
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* 查询Course
*/
public List<Course> find(Course course){
Connection conn = null;
PreparedStatement psmt = null;
ResultSet rs = null;
List<Course> list = new ArrayList<Course>();
try {
conn = DBUtils.getConnection();
StringBuffer buffer = new StringBuffer(“select * from course where 1=1”);
if(StringUtils.isNotEmpty(course.getCname())){
buffer.append(” and cname like ‘%”+course.getCname()+“%'”);
}
if(StringUtils.isNotEmpty(course.getTname())){
buffer.append(” and tname like ‘%”+course.getTname()+“%'”);
}
if(0 != course.getId()){
buffer.append(” and id = “+course.getId()+“”);
}
psmt = conn.prepareStatement(buffer.toString());
rs = psmt.executeQuery();
Course courseParam = null;
while(rs.next()){
courseParam = new Course();
courseParam.setId(rs.getInt(“id”));
courseParam.setCname(rs.getString(“cname”));
courseParam.setTname(rs.getString(“tname”));
list.add(courseParam);
}
DBUtils.close(conn, psmt, rs);
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
}
ScoreDao操作实体类:
package com.score.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import com.score.model.Score;
import com.score.model.ScoreCustom;
import com.score.utils.DBUtils;
/**
* ScoreDao操作实体类
*/
public class ScoreDao {
/**
* 添加Score
*/
public void insert(Score score){
Connection conn = null;
PreparedStatement psmt = null;
try {
conn = DBUtils.getConnection();
String sql = “insert into score(stu_id,cou_id,score) values(?,?,?)”;
psmt = conn.prepareStatement(sql);
psmt.setInt(1, score.getStuId());
psmt.setInt(2, score.getCouId());
psmt.setFloat(3, score.getScore());
psmt.executeUpdate();
DBUtils.close(conn, psmt);
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
*修改Score
*/
public void update(Score score){
Connection conn = null;
PreparedStatement psmt = null;
try {
conn = DBUtils.getConnection();
String sql = “update score set stu_id=?,cou_id=?,score=? where id = ?”;
psmt = conn.prepareStatement(sql);
psmt.setInt(1, score.getStuId());
psmt.setInt(2, score.getCouId());
psmt.setFloat(3, score.getScore());
psmt.setInt(4, score.getId());
psmt.executeUpdate();
DBUtils.close(conn, psmt);
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* 删除Score
*/
public void delete(int id){
Connection conn = null;
PreparedStatement psmt = null;
try {
conn = DBUtils.getConnection();
String sql = “delete from score where id = ?”;
psmt = conn.prepareStatement(sql);
psmt.setInt(1, id);
psmt.executeUpdate();
DBUtils.close(conn, psmt);
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* 查询成绩关联查询学生和课程
*/
public List<ScoreCustom> find(Score score){
Connection conn = null;
PreparedStatement psmt = null;
ResultSet rs = null;
List<ScoreCustom> list = new ArrayList<ScoreCustom>();
try {
conn = DBUtils.getConnection();
StringBuffer buffer = new StringBuffer(“select t1.`name`,t1.classname,t2.cname,t3.* from student t1,course t2,score t3 “);
buffer.append(” where t1.id = t3.stu_id and t2.id = t3.cou_id”);
if(0 != score.getStuId()){
buffer.append(” and t1.id = “+score.getStuId()+“”);
}
if(0 != score.getCouId()){
buffer.append(” and t2.id = “+score.getCouId()+“”);
}
psmt = conn.prepareStatement(buffer.toString());
rs = psmt.executeQuery();
ScoreCustom scoreParam = null;
while(rs.next()){
scoreParam = new ScoreCustom();
scoreParam.setId(rs.getInt(“id”));
scoreParam.setStuId(rs.getInt(“stu_id”));
scoreParam.setCouId(rs.getInt(“cou_id”));
scoreParam.setScore(rs.getFloat(“score”));
scoreParam.setName(rs.getString(“name”));
scoreParam.setClassname(rs.getString(“classname”));
scoreParam.setCname(rs.getString(“cname”));
list.add(scoreParam);
}
DBUtils.close(conn, psmt, rs);
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
/**
* 根据课程id和学号查询数量
* @param score
* @return
*/
public int countByStuIdAndCouId(Score score){
Connection conn = null;
PreparedStatement psmt = null;
ResultSet rs = null;
try {
conn = DBUtils.getConnection();
StringBuffer buffer = new StringBuffer(“select count(*) size from score where stu_id=? and cou_id=?”);
psmt = conn.prepareStatement(buffer.toString());
psmt.setInt(1, score.getStuId());
psmt.setInt(2, score.getCouId());
rs = psmt.executeQuery();
if(rs.next()){
return rs.getInt(“size”);
}
}catch (Exception e) {
e.printStackTrace();
}
return 0;
}
}
StudentDao操作实体类:
package com.score.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import com.score.model.Student;
import com.score.utils.DBUtils;
/**
* StudentDao操作实体类
*/
public class StudentDao {
/**
* 添加Student
*/
public void insert(Student student){
Connection conn = null;
PreparedStatement psmt = null;
try {
conn = DBUtils.getConnection();
String sql = “insert into student(classname,name) values(?,?)”;
psmt = conn.prepareStatement(sql);
psmt.setString(1, student.getClassname());
psmt.setString(2, student.getName());
psmt.executeUpdate();
DBUtils.close(conn, psmt);
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
*修改Student
*/
public void update(Student student){
Connection conn = null;
PreparedStatement psmt = null;
try {
conn = DBUtils.getConnection();
String sql = “update student set classname=?,name=? where id = ?”;
psmt = conn.prepareStatement(sql);
psmt.setString(1, student.getClassname());
psmt.setString(2, student.getName());
psmt.setInt(3, student.getId());
psmt.executeUpdate();
DBUtils.close(conn, psmt);
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* 删除Student
*/
public void delete(int id){
Connection conn = null;
PreparedStatement psmt = null;
try {
conn = DBUtils.getConnection();
String sql = “delete from student where id = ?”;
psmt = conn.prepareStatement(sql);
psmt.setInt(1, id);
psmt.executeUpdate();
DBUtils.close(conn, psmt);
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* 查询Student
*/
public List<Student> find(Student student){
Connection conn = null;
PreparedStatement psmt = null;
ResultSet rs = null;
List<Student> list = new ArrayList<Student>();
try {
conn = DBUtils.getConnection();
StringBuffer buffer = new StringBuffer(“select * from student where 1=1”);
if(StringUtils.isNotEmpty(student.getClassname())){
buffer.append(” and classname like ‘%”+student.getClassname()+“%'”);
}
if(StringUtils.isNotEmpty(student.getName())){
buffer.append(” and name like ‘%”+student.getName()+“%'”);
}
if(0 != student.getId()){
buffer.append(” and id = “+student.getId()+“”);
}
psmt = conn.prepareStatement(buffer.toString());
rs = psmt.executeQuery();
Student studentParam = null;
while(rs.next()){
studentParam = new Student();
studentParam.setId(rs.getInt(“id”));
studentParam.setClassname(rs.getString(“classname”));
studentParam.setName(rs.getString(“name”));
list.add(studentParam);
}
DBUtils.close(conn, psmt, rs);
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
}
UserDao操作实体类:
package com.score.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.score.model.User;
import com.score.utils.DBUtils;
/**
* UserDao操作实体类
*/
public class UserDao {
/**
* 根据账号密码查询
* @param user
* @return
*/
public User findByUnameAndPwd(User user){
Connection conn = null;
PreparedStatement psmt = null;
ResultSet rs = null;
User userParam = null;
try {
conn = DBUtils.getConnection();
StringBuffer buffer = new StringBuffer(“select * from `user` where uname=123 and pwd=?”);
psmt = conn.prepareStatement(buffer.toString());
psmt.setString(1, user.getUname());
psmt.setString(2, user.getPwd());
rs = psmt.executeQuery();
if(rs.next()){
userParam = new User();
userParam.setId(rs.getInt(“id”));
userParam.setUname(rs.getString(“uname”));
userParam.setPwd(rs.getString(“pwd”));
}
DBUtils.close(conn, psmt, rs);
} catch (Exception e) {
e.printStackTrace();
}
return userParam;
}
}
4.2 Package model
【1】 模块概述
Course实体类、Score实体类、Student实体类、User实体类。
【2】 代码实现
以Course实体类为例,进行创建:
package com.score.model;
/**
* Course实体类
*/
public class Course {
private int id;// 课程号
private String cname;// 课程名称
private String tname;// 教师
public Course(String cname, String tname) {
super();
this.cname = cname;
this.tname = tname;
}
public Course(int id, String cname, String tname) {
super();
this.id = id;
this.cname = cname;
this.tname = tname;
}
public Course() {
super();
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getCname() {
return cname;
}
public void setCname(String cname) {
this.cname = cname;
}
public String getTname() {
return tname;
}
public void setTname(String tname) {
this.tname = tname;
}
}
4.3 Package utils
【1】 模块概述
CommontUtils和DBUtils。
【2】 代码实现
CommonUtils:
package com.score.utils;
import java.util.Iterator;
import java.util.List;
import com.score.dao.CourseDao;
import com.score.model.Course;
public class CommonUtils {
private static CourseDao courseDao = new CourseDao();
//获取所有的课程名称
public static String[] getAllCourseName(){
List<Course> list = courseDao.find(new Course());
String[] arr = new String[list.size()];
for (int i = 0; i < arr.length; i++) {
arr[i] = list.get(i).getCname();
}
return arr;
}
//获取课程id
public static int getCourseIdByCourseName(String courseName){
List<Course> list = courseDao.find(new Course());
for (Course course : list) {
if(course.getCname().equals(courseName)){
return course.getId();
}
}
return 0;
}
}
DBUtils:
package com.score.utils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class DBUtils {
private static String url=“jdbc:mysql://localhost:3306/db_score”;
private static String username=“root”;
private static String password=“root”;
private static String driver=“com.mysql.jdbc.Driver”;
static{
try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static Connection getConnection() throws SQLException{
return DriverManager.getConnection(url, username, password);
}
public static void close(Connection conn,PreparedStatement psmt, ResultSet rs){
if(rs != null){try{rs.close();}catch(SQLException e){e.printStackTrace();}}
if(psmt != null){try{psmt.close();}catch(SQLException e){e.printStackTrace();}}
if(conn != null){try{conn.close();}catch(SQLException e){e.printStackTrace();}}
}
public static void close(Connection conn,PreparedStatement psmt){
close(conn,psmt,null);
}
// public static void main(String[] args) {
// try {
// System.out.println(“数据库连接成功“);
// DBUtils.getConnection();
// } catch (SQLException e) {
// e.printStackTrace();
// }
// }
}
4.4 Package views
【1】 模块概述
AddScoreFrm、CourseManageFrm、LoginFrm、MenuFrm、ScoreManageFrm和StudentManageFrm。
【2】 代码实现
以AddScoreFrm为例:
package com.score.views;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import com.score.dao.ScoreDao;
import com.score.model.Score;
import com.score.utils.CommonUtils;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class AddScoreFrm extends JFrame {
private JPanel contentPane;
private JTextField stu_idTxt;
private JTextField scoreTxt;
private JComboBox comboBox;
private ScoreDao scoreDao = new ScoreDao();
/*public static void main(String[] args) {
AddScoreFrm frame = new AddScoreFrm();
frame.setVisible(true);
}*/
public AddScoreFrm() {
setTitle(“学生成绩管理系统–添加成绩“);
setBounds(100, 100, 450, 300);
setResizable(false);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel label = new JLabel(“学号“);
label.setBounds(105, 32, 54, 15);
contentPane.add(label);
stu_idTxt = new JTextField();
stu_idTxt.setBounds(137, 29, 162, 21);
contentPane.add(stu_idTxt);
stu_idTxt.setColumns(10);
JLabel label_1 = new JLabel(“课程“);
label_1.setBounds(105, 75, 29, 15);
contentPane.add(label_1);
comboBox = new JComboBox();
comboBox.setModel(new DefaultComboBoxModel(CommonUtils.getAllCourseName()));//从数据库中查询所有课程名字,填充到下拉条
comboBox.setBounds(137, 72, 162, 21);
contentPane.add(comboBox);
JLabel label_2 = new JLabel(“分数“);
label_2.setBounds(105, 120, 54, 15);
contentPane.add(label_2);
scoreTxt = new JTextField();
scoreTxt.setBounds(137, 117, 162, 21);
contentPane.add(scoreTxt);
scoreTxt.setColumns(10);
JButton button = new JButton(“添加成绩“);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int id = Integer.parseInt(stu_idTxt.getText());
int courseId = CommonUtils.getCourseIdByCourseName(comboBox.getSelectedItem().toString());
float score = Float.parseFloat(scoreTxt.getText());
if(0 != scoreDao.countByStuIdAndCouId(new Score(id, courseId))){
JOptionPane.showMessageDialog(null, “失败,这个学生和课程已经添加过成绩了!“);
return;
}
scoreDao.insert(new Score(id, courseId, score));
JOptionPane.showMessageDialog(null, “添加成功“);
stu_idTxt.setText(“”);
scoreTxt.setText(“”);
}
});
button.setBounds(137, 169, 93, 23);
contentPane.add(button);
}
}
5、项目小结
对于学生信息管理系统项目,由于时间较短,不熟悉数据库和idea的建立过程,只完成了部分功能。该数据库只有一个学生基本信息表,实现了添加、删除、修改和查询功能,并实现了登录界面的设计。缺点是对学生基本信息表的数据格式没有严格要求。
通过研究和实践,我基本上可以了解创建一个用户友好的项目管理系统和应用界面。如果我有足够的时间,我会设计登录界面,指定三个登录人员:管理员、教师和学生,然后管理员可以对教师和学生进行授权和授权,学生可以添加、删除、修改和检查他们的选课信息。他们只能查看课程分数和其他人的信息。教师可以添加、删除、修改和检查学生的成绩和基本信息等。
- 基于Java Web的渭南市大荔县图书管理系统的设计与实现 电子设计工程. 2021,29(24)
- Database Management System:An Evolutionary Approach 作者:Jagdish Chandra Patni; Hitesh Kumar Sharma; Ravi Tomar; Avita Katal
- 基于云数据库的高校学生网络党建管理系统设计 微型电脑应用. 2021,37(12)