简单学生管理

目录

一、 需求分析

二、数据库

三、实体类

 五、界面


一、 需求分析

1)建表

        需要建立四张表,分别为班级表、学生表、教师表、爱好表

        班级表字段:班级编号、班级名称

        学生表字段:学生id、学生姓名、班级编号、教员编号、爱好id

        教师表字段:教员id、教员名称、所教班级

         爱好表字段:爱好id、爱好名称  

2)查询

可以多条件查询:根据班级、教师、爱好进行查询

3)新增

4)修改

修改要注意值得回显

5)分页

显示第几页,共几页,总记录多少条数据,可以选定页面跳转

6)删除

二、数据库

1)新建数据库以及表

        

 2)添加值,以便测试

三、实体类

1)根据数据库的表建立所需实体类

  2) 给实体类定义变量以及所需构造方法

例如:

package com.mgy.entity;

import java.io.Serializable;
import java.util.List;

/**
 * 实体类:学生类
 * @author Administrator
 *
 */
public class Student implements Serializable{
	
	private static final long serialVersionUID = 1L;
	
	private int sid;//学生编号
	private String sname;//学生名称
	private Cla cl;//班级对象
	private Theaher th;//教员对象
	private List<Hobby> hy;//爱好集合

	public int getSid() {
		return sid;
	}
	public void setSid(int sid) {
		this.sid = sid;
	}
	public String getSname() {
		return sname;
	}
	public void setSname(String sname) {
		this.sname = sname;
	}
	public Cla getCl() {
		return cl;
	}
	public void setCl(Cla cl) {
		this.cl = cl;
	}
	public Theaher getTh() {
		return th;
	}
	public void setTh(Theaher th) {
		this.th = th;
	}
	public List<Hobby> getHy() {
		return hy;
	}
	public void setHy(List<Hobby> hy) {
		this.hy = hy;
	}
	public Student() {
		// TODO Auto-generated constructor stub
	}
	public Student(int sid, String sname, Cla cl, Theaher th, List<Hobby> hy) {
		this.sid = sid;
		this.sname = sname;
		this.cl = cl;
		this.th = th;
		this.hy = hy;
	}
	public Student(String sname, Cla cl, Theaher th, List<Hobby> hy) {
		this.sname = sname;
		this.cl = cl;
		this.th = th;
		this.hy = hy;
	}
	@Override
	public String toString() {
		return "Student [sid=" + sid + ", sname=" + sname + ", cl=" + cl + ", th=" + th + ", hy=" + hy + "]";
	}
	
}

四、mvc模式
1)定义数据库辅助类

package com.mgy.util;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

/**
 * 数据库辅助类
 * 提供了一组获得或关闭数据库对象的方法
 * 
 */
public class DBHelper {
	private static String driver;
	private static String url;
	private static String user;
	private static String password;

	static {// 静态块执行一次,加载 驱动一次
		try {
			InputStream is = DBHelper.class
					.getResourceAsStream("config.properties");

			Properties properties = new Properties();
			properties.load(is);

			driver = properties.getProperty("driver");
			url = properties.getProperty("url")
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值