JavaSwing + Mybatis 学生信息管理系统(增删改查)

JavaSwing + Mybatis 学生信息管理系统

这是最近两天做的项目(非常简陋,代码也比较臃肿,但是功能基本还是实现),实现了学生信息的增删改查功能

  • 项目结构&jar包
    -在这里插入图片描述
    在这里插入图片描述

1. 登录页面
1.1页面效果
在这里插入图片描述

1.2页面代码。

public class Login extends JFrame implements ActionListener{
	private JLabel jl_title,jl_id,jl_password,jl_code;
	private JTextField jtf_num,jtf_code;
	private JPasswordField jpf_password;
	private JButton jb_login,jb_exit,jb_code;
	private ImageIcon icon;
	private Code code =	new Code();
	public Login() {
		getContentPane().setLayout(null);
		this.setSize(445, 350);
		this.setTitle("学生信息管理系统");
	
		jl_title = new JLabel("学生信息管理系统");
		jl_title.setFont(new Font("微软雅黑", Font.BOLD, 25));
		jl_title.setBounds(121, 10, 200, 56);
		getContentPane().add(jl_title);
		
		jl_id = new JLabel("账   号");
		jl_id.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		jl_id.setBounds(67, 88, 58, 31);
		getContentPane().add(jl_id);
		
		jtf_num = new JTextField();
		jtf_num.setBounds(135, 89, 224, 31);
		getContentPane().add(jtf_num);
		jtf_num.setColumns(10);
		
		jl_password = new JLabel("密   码");
		jl_password.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		jl_password.setBounds(67, 145, 54, 31);
		getContentPane().add(jl_password);
		
		jpf_password = new JPasswordField();
		jpf_password.setBounds(135, 146, 224, 31);
		getContentPane().add(jpf_password);
		
		jb_login = new JButton("登 录");
		jb_login.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		jb_login.setBounds(83, 251, 110, 31);
		getContentPane().add(jb_login);
		
		jb_exit = new JButton("退 出");
		jb_exit.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		jb_exit.setBounds(232, 251, 110, 31);
		getContentPane().add(jb_exit);
		
		jl_code = new JLabel("验证码");
		jl_code.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		jl_code.setBounds(67, 192, 54, 31);
		getContentPane().add(jl_code);
		
		icon = new ImageIcon(code.codeImage());	
		jb_code = new JButton();
		jb_code.setBounds(233, 187, 126, 44);
		jb_code.setIcon(icon);
		getContentPane().add(jb_code);
		
		jtf_code = new JTextField();
		jtf_code.setBounds(135, 187, 88, 43);
		getContentPane().add(jtf_code);
		
		
		jb_login.addActionListener(this);
		jb_exit.addActionListener(this);
		jb_code.addActionListener(this);
		
		this.setVisible(true);
		this.setResizable(false);
	}
}

1.3处理方法

public void actionPerformed(ActionEvent e) {
		
		if (e.getSource()==jb_login) {	
			String aId = jtf_num.getText();
			String aPassword = jpf_password.getText();
			String co =  jtf_code.getText();
			if (code.verify(co)) {
			    SqlSession openSession = null;
				try {
					openSession = new  SqlSessionFactoryTool().getSqlSession();
					mapper login = openSession.getMapper(mapper.class);
					Admin admin = login.login(aId, aPassword);
					if (admin != null) {
						//保存临时变量
						TAdmin.setaId(admin.getaId());
						TAdmin.setaName(admin.getaName());
						TAdmin.setaPassword(admin.getaPassword());
						JOptionPane.showMessageDialog(this,"登录成功!","提示",JOptionPane.INFORMATION_MESSAGE);
						mune mune = new mune();
						Toolkit tookit = mune.getToolkit();
						Dimension dm = tookit.getScreenSize();
						mune.setLocation((dm.width - mune.getWidth()) / 2,
								(dm.height - mune.getHeight()) / 2);
						mune.setVisible(true);
						this.dispose();
					}else {
						JOptionPane.showMessageDialog(this,"账号或密码错误!","提示",JOptionPane.INFORMATION_MESSAGE);
						icon.setImage(code.newCodeImage());
					}					
				} catch (IOException e1) {
					JOptionPane.showMessageDialog(this,"登录失败!","提示",JOptionPane.INFORMATION_MESSAGE);
					e1.printStackTrace();
				}
				finally {
					openSession.close();
				}
			}else {
				JOptionPane.showMessageDialog(this,"验证码错误,请重试!","提示",JOptionPane.INFORMATION_MESSAGE);
				icon.setImage(code.newCodeImage());
			}		
		}
		if (e.getSource()==jb_exit) {
			int exitChoose = JOptionPane.showConfirmDialog(this, "是否要退出本系统?", "退出系统", JOptionPane.OK_CANCEL_OPTION);
			if (exitChoose == JOptionPane.OK_OPTION) {
				System.exit(0);
			} else {
				return;
			}
		}
		if (e.getSource()==jb_code) {			
			
			icon.setImage(code.newCodeImage());
		}
	}

1.4验证码、保存用户信息和返回SqlSession的工具类
1.4.1验证码
这里我用到了hutool工具类的jar包

public class Code {
	private LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(126, 44);
	
	//获取初始验证图片
	public Image codeImage(){
		//System.out.println(lineCaptcha.getCode());
		return lineCaptcha.createImage(lineCaptcha.getCode());
	}
	//重新生成验证码和图片
	public Image newCodeImage() {
		lineCaptcha.createCode();
		//System.out.println(lineCaptcha.getCode());
		return lineCaptcha.createImage(lineCaptcha.getCode());
	}
	//验证验证是否正确
	public Boolean verify(String code) {
		//System.out.println("code:"+code);
		return lineCaptcha.verify(code);
	}
	
}

1.4.2保存类对象临时信息类

public class TAdmin {
	
	private static Integer aId = null;
	private static String aName = null;
	private static String aPassword = null;
	public static Integer getaId() {
		return aId;
	}
	public static void setaId(Integer aId) {
		TAdmin.aId = aId;
	}
	public static String getaName() {
		return aName;
	}
	public static void setaName(String aName) {
		TAdmin.aName = aName;
	}
	public static String getaPassword() {
		return aPassword;
	}
	public static void setaPassword(String aPassword) {
		TAdmin.aPassword = aPassword;
	}
}

1.4.3 返回SqlSession操作对象类

public class SqlSessionFactoryTool {
	
	public SqlSession  getSqlSession() throws IOException{
		String resource = "mybatis-config.xml"; 
		InputStream inputStream = Resources.getResourceAsStream(resource);
		SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
		SqlSession openSession = sqlSessionFactory.openSession();
		return openSession;
	}
}

2. 主页面
主页面中有一个jPanel组件,其它操作时就把组件内容用.removeAll()方法清楚所有内容,再调用相应的生成组件的类 调用Jpanel的add()方法,再调用getContentPane().add()添加jPanel组件(详细过程看处理方法)
2.1页面效果

List item
2.2 界面代码

public class mune extends JFrame implements ActionListener{
	private JButton jb_add,jb_update_password,jb_update,jb_delete,jb_select,jb_exit;
	private JPanel panel;
	private JLabel jl_title;
	private JLabel lblNewLabel;
	public mune() {
		
		this.setSize(700, 530);
		this.setTitle("学生信息管理系统");
		getContentPane().setLayout(null);
		
		jb_select = new JButton("查询学生信息");
		jb_select.setBounds(10, 50, 119, 36);
		jb_select.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		getContentPane().add(jb_select);
		
		jb_add = new JButton("添加学生信息");
		jb_add.setBounds(10, 110, 119, 36);
		jb_add.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		getContentPane().add(jb_add);
		
		jb_update = new JButton("修改学生信息");
		jb_update.setBounds(10, 170, 119, 36);
		jb_update.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		getContentPane().add(jb_update);
		
		jb_delete = new JButton("删除学生信息");
		jb_delete.setBounds(10, 240, 119, 36);
		jb_delete.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		getContentPane().add(jb_delete);
		
		jb_update_password = new JButton("修改登录密码");
		jb_update_password.setBounds(10, 310, 119, 36);
		jb_update_password.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		getContentPane().add(jb_update_password);
		
		jb_exit = new JButton("退出系统");
		jb_exit.setBounds(10, 380, 119, 36);
		jb_exit.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		getContentPane().add(jb_exit);
		
		panel = new JPanel();
		panel.setLayout(null);
		panel.setBounds(140, 10, 554, 481);
		
		getContentPane().add(panel);
		
		jl_title = new JLabel("学生信息管理系统");
		jl_title.setFont(new Font("微软雅黑", Font.PLAIN, 26));
		jl_title.setBounds(173, 10, 213, 36);
		panel.add(jl_title);
		
		lblNewLabel = new JLabel("欢迎使用本系统!");
		lblNewLabel.setForeground(Color.BLUE);
		lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 28));
		lblNewLabel.setBounds(162, 166, 224, 107);
		panel.add(lblNewLabel);
		
		jb_add.addActionListener(this);
		jb_update_password.addActionListener(this);
		jb_update.addActionListener(this);
		jb_delete.addActionListener(this);
		jb_select.addActionListener(this);
		jb_exit.addActionListener(this);
		
		this.setVisible(true);
		this.setResizable(false);
	}
}

2.3处理方法

public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if(e.getSource()==jb_add) {
			panel.removeAll();
			panel.add(new add().getAddJPanel());
			getContentPane().add(panel);
			this.repaint();
		}if(e.getSource()==jb_update_password) {
			panel.removeAll();
			panel.add(new updatePassword().getJpanel());
			getContentPane().add(panel);
			this.repaint();
		}if(e.getSource()==jb_update) {
			panel.removeAll();
			panel.add(new update().getUpdateJPanel());
			getContentPane().add(panel);
			this.repaint();
		}if(e.getSource()==jb_delete) {
			panel.removeAll();
			panel.add(new delete().getDelectJPanel());
			getContentPane().add(panel);
			this.repaint();
		}if(e.getSource()==jb_select) {
			panel.removeAll();
			panel.add(new selete().getSelectJPanel());
			getContentPane().add(panel);
			this.repaint();
		}if(e.getSource()==jb_exit) {
			int exitChoose = JOptionPane.showConfirmDialog(this, "是否要退出本系统?", "退出系统", JOptionPane.OK_CANCEL_OPTION);
			if (exitChoose == JOptionPane.OK_OPTION) {
				System.exit(0);
			} else {
				return;
			}
		}
	}

3. 查询页面
3.1页面效果(涉及信息的我就加了马赛克了),实现了多条件模糊分页查询,并显示页面,生成表格需要把数据转为二维数组
在这里插入图片描述
3.2页面代码

public class selete extends JPanel implements ActionListener {

	private JTable table;
	private JLabel jl_title, jl_name, jl_id, jl_di, jl_ye, jl_gong;
	private JTextField jtf_id, jtf_name, jft_go;
	private JPanel panel;
	private JButton jb_first, jb_up, jb_down, jb_seach, jb_jump;
	private JScrollPane line;
	private DefaultTableModel stuTable;
	private int page = 1, limit = 10, fristPage = 1, lastPage, count;
	private List<Student> students;
	private String[][] result = null;
	private SqlSession session = null;
	private static String[] columnNames = { "学号", "姓名", "性别", "生日", "年龄", "系别", "宿舍" };
	private JButton jb_last;

	public JPanel getSelectJPanel() {
		try {
			session = new SqlSessionFactoryTool().getSqlSession();
			mapper mapper = session.getMapper(mapper.class);
			students = mapper.selectStuBySomething(null, null, (page - 1) * limit, limit);
			count = mapper.countStu(null, null);
			lastPage = count / limit + 1;
		} catch (IOException e) {
			JOptionPane.showMessageDialog(null, e.getMessage(), "初始化失败!", JOptionPane.ERROR_MESSAGE);
		} finally {
			session.close();
		}
		setLayout(null);
		panel = new JPanel();
		panel.setSize(554, 481);
		panel.setLayout(null);

		jl_title = new JLabel("学生信息查询");
		jl_title.setFont(new Font("微软雅黑", Font.PLAIN, 26));
		jl_title.setBounds(174, 10, 165, 34);
		panel.add(jl_title);

		// 表格显示
		result = toArray(students);
		// 转为二维数组
		stuTable = new DefaultTableModel(result, columnNames) {
			public boolean isCellEditable(int row, int column) {
				return false;
			}
		};// 可以被选中但不可被编辑

		table = new JTable(stuTable);
		setWidth();
		table.setEnabled(false);
		line = new JScrollPane(table);
		line.setBounds(1, 117, 552, 313);
		panel.add(line);

		jl_id = new JLabel("学 号");
		jl_id.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		jl_id.setBounds(23, 63, 40, 25);
		panel.add(jl_id);

		jl_name = new JLabel("姓 名");
		jl_name.setBounds(210, 63, 40, 25);
		jl_name.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		panel.add(jl_name);

		jtf_id = new JTextField();
		jtf_id.setBounds(73, 63, 100, 25);
		jtf_id.setColumns(10);
		panel.add(jtf_id);

		jtf_name = new JTextField();
		jtf_name.setColumns(10);
		jtf_name.setBounds(262, 63, 100, 25);
		panel.add(jtf_name);

		jb_seach = new JButton("搜 索");
		jb_seach.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		jb_seach.setBounds(403, 63, 80, 25);
		panel.add(jb_seach);

		jb_first = new JButton("首页");
		jb_first.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		jb_first.setBounds(10, 450, 65, 25);
		panel.add(jb_first);

		jb_up = new JButton("上页");
		jb_up.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		jb_up.setBounds(73, 450, 65, 25);
		panel.add(jb_up);

		jb_down = new JButton("下页");
		jb_down.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		jb_down.setBounds(136, 450, 65, 25);
		panel.add(jb_down);

		jb_last = new JButton("尾页");
		jb_last.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		jb_last.setBounds(197, 450, 65, 25);
		panel.add(jb_last);

		jft_go = new JTextField();
		jft_go.setBounds(441, 453, 25, 20);
		panel.add(jft_go);
		jft_go.setColumns(10);

		jb_jump = new JButton("跳转");
		jb_jump.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		jb_jump.setBounds(483, 450, 65, 25);
		panel.add(jb_jump);

		jl_di = new JLabel("第");
		jl_di.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		jl_di.setBounds(427, 450, 14, 25);
		panel.add(jl_di);

		jl_ye = new JLabel("页");
		jl_ye.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		jl_ye.setBounds(466, 450, 14, 25);
		panel.add(jl_ye);

		jl_gong = new JLabel("当前第  " + page + " 页 共 " + (count / limit + 1) + " 页");
		jl_gong.setFont(new Font("微软雅黑", Font.PLAIN, 14));
		jl_gong.setBounds(275, 451, 142, 25);
		panel.add(jl_gong);

		jb_seach.addActionListener(this);
		jb_first.addActionListener(this);
		jb_up.addActionListener(this);
		jb_down.addActionListener(this);
		jb_last.addActionListener(this);
		jb_jump.addActionListener(this);

		panel.setVisible(true);

		return panel;
	}
}

3.3List转二维数组方法

private String[][] toArray(List<Student> stuList) {
		String[][] result = new String[students.size()][7];
		for (int i = 0; i < result.length; i++) {
			result[i][0] = students.get(i).getNum();
			result[i][1] = students.get(i).getName();
			result[i][2] = students.get(i).getGender();
			result[i][3] = students.get(i).getBirthday();
			result[i][4] = "" + students.get(i).getAge();
			result[i][5] = students.get(i).getMajor();
			result[i][6] = students.get(i).getDorm();
		}
		return result;
	}

3.4JTable设置列宽方法

// 设置表单列宽,每次更新完都有设置
	private void setWidth() {
		table.setRowHeight(29);
		table.getColumnModel().getColumn(2).setPreferredWidth(40);
		table.getColumnModel().getColumn(4).setPreferredWidth(40);
		table.getColumnModel().getColumn(5).setPreferredWidth(110);
		table.getColumnModel().getColumn(6).setPreferredWidth(110);
		table.setRowSelectionAllowed(false);
	}

3.5处理方法

@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == jb_seach) {
			String num = jtf_id.getText();
			String name = jtf_name.getText();
			try {
				session = new SqlSessionFactoryTool().getSqlSession();
				mapper mapper = session.getMapper(mapper.class);
				page = fristPage;
				students = mapper.selectStuBySomething(num, name, (page - 1) * limit, limit);
				count = mapper.countStu(num, name);
				lastPage = count / limit + 1;
				result = toArray(students);
				jl_gong.setText("当前第  " + page + " 页 共 " + (count / limit + 1) + " 页");
				stuTable.setDataVector(result, columnNames);
				setWidth();
				jft_go.setText("");
				panel.repaint();

			} catch (IOException e1) {

				e1.printStackTrace();
			} finally {
				session.close();
			}
		}
		if (e.getSource() == jb_first) {
			if (page == 1) {
				JOptionPane.showMessageDialog(this, "当前为首页 !", "提示", JOptionPane.INFORMATION_MESSAGE);
			} else {
				String num = jtf_id.getText();
				String name = jtf_name.getText();
				try {
					session = new SqlSessionFactoryTool().getSqlSession();
					mapper mapper = session.getMapper(mapper.class);
					page = fristPage;
					students = mapper.selectStuBySomething(num, name, (page - 1) * limit, limit);
					count = mapper.countStu(num, name);
					lastPage = count / limit + 1;
					result = toArray(students);
					jl_gong.setText("当前第  " + page + " 页 共 " + (count / limit + 1) + " 页");
					stuTable.setDataVector(result, columnNames);
					setWidth();
					panel.repaint();

				} catch (IOException e1) {

					e1.printStackTrace();
				} finally {
					session.close();
				}
			}
		}
		if (e.getSource() == jb_up) {
			if (page == 1) {
				JOptionPane.showMessageDialog(this, "当前为首页 !", "提示", JOptionPane.INFORMATION_MESSAGE);
			} else {
				String num = jtf_id.getText();
				String name = jtf_name.getText();
				page = page - 1;
				try {
					session = new SqlSessionFactoryTool().getSqlSession();
					mapper mapper = session.getMapper(mapper.class);
					students = mapper.selectStuBySomething(num, name, (page - 1) * limit, limit);
					count = mapper.countStu(num, name);
					jl_gong.setText("当前第  " + page + " 页 共 " + (count / limit + 1) + " 页");
					result = toArray(students);
					stuTable.setDataVector(result, columnNames);
					setWidth();
					panel.repaint();

				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} finally {
					session.close();
				}
			}
		}
		if (e.getSource() == jb_down) {
			if (page == lastPage) {
				JOptionPane.showMessageDialog(this, "当前为最后一页 !", "提示", JOptionPane.INFORMATION_MESSAGE);
			} else {
				String num = jtf_id.getText();
				String name = jtf_name.getText();
				page = page + 1;
				try {
					session = new SqlSessionFactoryTool().getSqlSession();
					mapper mapper = session.getMapper(mapper.class);
					students = mapper.selectStuBySomething(num, name, (page - 1) * limit, limit);
					count = mapper.countStu(num, name);
					jl_gong.setText("当前第  " + page + " 页 共 " + (count / limit + 1) + " 页");
					result = toArray(students);
					stuTable.setDataVector(result, columnNames);
					setWidth();
					panel.repaint();

				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} finally {
					session.close();
				}
			}
		}
		if (e.getSource() == jb_last) {
			if (page == lastPage) {
				JOptionPane.showMessageDialog(this, "当前为最后一页 !", "提示", JOptionPane.INFORMATION_MESSAGE);
			} else {
				String num = jtf_id.getText();
				String name = jtf_name.getText();
				page = lastPage;
				try {
					session = new SqlSessionFactoryTool().getSqlSession();
					mapper mapper = session.getMapper(mapper.class);
					students = mapper.selectStuBySomething(num, name, (page - 1) * limit, limit);
					count = mapper.countStu(num, name);
					jl_gong.setText("当前第  " + page + " 页 共 " + (count / limit + 1) + " 页");
					result = toArray(students);
					stuTable.setDataVector(result, columnNames);
					setWidth();
					panel.repaint();

				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} finally {
					session.close();
				}
			}
		}
		if (e.getSource() == jb_jump) {
			String num = jtf_id.getText();
			String name = jtf_name.getText();
			String toPage = jft_go.getText();
			try {
				page = Integer.parseInt(toPage);
			} catch (Exception e2) {
				JOptionPane.showMessageDialog(this, "只能输入数字 !", "提示", JOptionPane.INFORMATION_MESSAGE);
			}
			if (page < fristPage || page > lastPage) {
				JOptionPane.showMessageDialog(this, "请输入正确的范围 !", "提示", JOptionPane.INFORMATION_MESSAGE);
				return ;
			}
			try {
				session = new SqlSessionFactoryTool().getSqlSession();
				mapper mapper = session.getMapper(mapper.class);
				students = mapper.selectStuBySomething(num, name, (page - 1) * limit, limit);
				count = mapper.countStu(num, name);
				jl_gong.setText("当前第  " + page + " 页 共 " + (count / limit + 1) + " 页");
				result = toArray(students);
				stuTable.setDataVector(result, columnNames);
				setWidth();
				panel.repaint();
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} finally {
				session.close();
			}
		}
	}

4. 其它页面

  • 都是页面代码,没什么特别的地方,所以不展示出来了

5. 数据操作
5.1 Mybatis配置

<?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE configuration  PUBLIC "-//mybatis.org//DTD Config 3.0//EN" 
  "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>	
	<environments default="development">
		<environment id="development">
			<transactionManager type="JDBC" />
			<dataSource type="POOLED">
				<property name="driver" value="com.mysql.jdbc.Driver" />
				<property name="url" value="jdbc:mysql://localhost:3306/studentsm" />
				<property name="username" value="root" />
				<property name="password" value="root" />
			</dataSource>
		</environment>
	</environments>
	<mappers>
		<mapper resource="mapper.xml" /> 
	</mappers>
</configuration>

5.2 mapper接口

public interface mapper {
	//管理员登录
	public Admin login(@Param("aName")String aName,@Param("aPassword")String aPassword);
	//管理员登录修改密码
	public Integer updatePassword(Admin admin);
	//根据Id查询学生信息
	public Student selectStuByNum(String num);
	//多条件查询学生信息并分页
	public List<Student> selectStuBySomething(@Param("num")String num,@Param("name")String name,
																	@Param("page")Integer page,@Param("limit")Integer limit);
	//多条件查询符合要求学生的总数
	public Integer countStu(@Param("num")String num,@Param("name")String name);
	//根据Id删除学生信息
	public Integer deleteStu(String num);
	//根据Id修改学生信息
	public Integer updateStu(Student student);
	//添加学生信息
	public Integer addStu(Student student);
}

5.3 mapper实现
不展示

  • 5
    点赞
  • 47
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
### 回答1: 学生信息管理系统是一种用于维护学生信息的软件系统。下面是一种使用Java语言编写学生信息管理系统的方法: 1. 首先,需要创建一个学生类,用于存储学生信息学生类应该包含至少如下属性: 学号、姓名、年龄、性别、专业等。 2. 然后,需要创建一个学生信息管理类,用于维护学生信息。这个类应该包含如下功能: - 增加学生信息 - 删除学生信息 - 修学生信息 - 学生信息 - 显示所有学生信息 3. 最后,需要创建一个主类,用于测试学生信息管理系统的功能。在主类中,可以创建一个学生信息管理对象,并调用其中的方法来测试系统的功能。 下面是一个示例代码,展示了如何创建学生类和学生信息管理类: ``` // 学生类 public class Student { private String studentId; // 学号 private String name; // 姓名 private int age; // 年龄 private String gender; // 性别 private String major; // 专业 // 省略构造函数、getter和setter方法 } // 学生信息管理类 import java.util.ArrayList; import java.util.List; public class StudentManager { private List<Student> students; // 存储学 ### 回答2: 学生信息管理系统是一个用来管理学生的基本信息的软件系统。使用Java语言编写学生信息管理系统可以提供一个简单、高效、易于维护和扩展的解决方案。 首先,我们需要定义学生类,包括学生的基本信息,例如姓名、学号、性别、出生日期等。通过定义适当的类变量和方法,可以在系统中对学生信息进行增、删、等操作。 其次,我们可以设计一个学生信息管理系统的用户界面,使用Java的Swing或JavaFX等图形界面库,通过使用按钮、文本框等控件来实现用户与系统的交互。例如,可以设计一个主界面,用户可以在界面中输入学生信息,并选择进行相应的操作。 在编写学生信息管理系统的过程中,我们可以使用MySQL等关系型数据库,将学生信息存储在数据库中。通过使用JDBC或者ORM框架(例如Hibernate或MyBatis)来实现Java程序与数据库的连接和操作。 在系统中,我们可以提供以下功能: 1. 添加学生信息:用户可以输入学生的基本信息,并将其保存到数据库中。 2. 学生信息:用户可以根据学号、姓名等条件学生信息,并在系统中显示结果。 3. 更新学生信息:用户可以选择需要更新的学生,并修其基本信息。 4. 删除学生信息:用户可以选择需要删除的学生,并把其从数据库中删除。 最后,我们可以通过对系统进行测试和调试来确保其正确运行,并进行优化以提高系统的性能和用户体验。 综上所述,使用Java语言编写学生信息管理系统可以提供一个方便、可靠的解决方案,帮助学校、教育机构等管理学生的基本信息。 ### 回答3: 学生信息管理系统是一种用于记录和管理学生的个人和学术信息的软件应用程序。它与学生、教师和学校管理人员之间的信息交流和管理非常重要。通过使用Java编程语言,我们可以创建一个功能强大的学生信息管理系统。 首先,我们需要设计一个学生类,该类应该包括用于存储学生姓名、年龄、性别、学号等信息的实例变量。我们可以使用Java的封装原则来确保数据的安全性和一致性。 其次,我们可以创建一个学生信息管理系统的主类。在该类中,我们可以实例化学生对象,并使用ArrayList或HashMap等数据结构将学生对象存储起来。 接下来,我们可以实现一些基本功能,例如添加学生、删除学生、修学生信息学生等功能。这些功能可以通过编写相应的方法来实现。例如,添加学生功能可以通过调用ArrayList的add()方法向列表中添加学生对象来实现。 然后,我们可以实现一些高级功能,例如按照姓名、年龄或学号对学生进行排序。这可以通过使用Java提供的排序算法或自定义比较器来实现。 此外,我们可以为学生信息管理系统添加用户界面,以便用户可以更方便地使用系统。我们可以使用Java Swing或JavaFX等库来创建用户界面,并将其与系统逻辑相连接。 最后,我们可以进行系统的测试和调试,确保其功能和性能正常运行。我们可以使用不同的测试数据来验证系统的稳定性和准确性。 通过以上步骤,我们可以使用Java编程语言创建一个功能齐全的学生信息管理系统。它可以帮助学生、教师和学校管理人员更有效地管理学生信息,提高教学和管理效率。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值