student增删改查

3 篇文章 0 订阅

目录

一,底层代码:

                ①DBHelper

                ②实体类student

                ③数据库访问层  dao

                ④业务逻辑层  biz

                ⑤ 控制层 servlet

二,界面:

                ①主界面:

                ②增加界面:

                ③修改界面:

                ④查看界面:

三,功能展示

        ①查看

        ②增加

        ③修改

        ④删除


一,底层代码:

                ①DBHelper

                

内置文件:

完整代码:

#mysql
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/0613?useUnicode=true&characterEncoding=UTF-8&useSSL=false
user=root
pwd=123456
 

方法:


完整代码:

package com.ruojuan.util;

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

/**
 * 数据库辅助类
 * @author liuruojuan
 *
 * 时间:2022年6月14日上午9:14:34
 */

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");
			user = properties.getProperty("user");
			password = properties.getProperty("pwd");

			Class.forName(driver);
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	/**
	 * 获得数据连接对象
	 * 
	 * @return
	 */
	public static Connection getConnection() {
		try {
			Connection conn = DriverManager.getConnection(url, user, password);
			return conn;
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public static void close(ResultSet rs) {
		if (null != rs) {
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
				throw new RuntimeException(e);
			}
		}
	}

	public static void close(Statement stmt) {
		if (null != stmt) {
			try {
				stmt.close();
			} catch (SQLException e) {
				e.printStackTrace();
				throw new RuntimeException(e);
			}
		}
	}

	public static void close(Connection conn) {
		if (null != conn) {
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
				throw new RuntimeException(e);
			}
		}
	}
	
	public static void close(PreparedStatement ps) {
		if (null != ps) {
			try {
				ps.close();
			} catch (SQLException e) {
				e.printStackTrace();
				throw new RuntimeException(e);
			}
		}
	}

	public static void close(Connection conn, Statement stmt, ResultSet rs) {
		close(rs);
		close(stmt);
		close(conn);
	}
	
	public static void close(Connection conn, Statement stmt, ResultSet rs,PreparedStatement ps) {
		close(rs);
		close(stmt);
		close(conn);
		close(ps);
	}

	public static boolean isOracle() {
		return "oracle.jdbc.driver.OracleDriver".equals(driver);
	}

	public static boolean isSQLServer() {
		return "com.microsoft.sqlserver.jdbc.SQLServerDriver".equals(driver);
	}
	
	public static boolean isMysql() {
		return "com.mysql.jdbc.Driver".equals(driver);
	}

	public static void main(String[] args) {
		Connection conn = DBHelper.getConnection();
		DBHelper.close(conn);
		System.out.println("isOracle:" + isOracle());
		System.out.println("isSQLServer:" + isSQLServer());
		System.out.println("isMysql:" + isMysql());
		System.out.println("数据库连接(关闭)成功");
	}
	
	
}

                ②实体类student

Class类(班级类):

package com.ruojuan.entity;

import java.io.Serializable;

/**
 * 班级实体类
 * @author liuruojuan
 *
 * 时间:2022年6月18日下午7:31:56
 */
public class Class implements Serializable{

	private static final long serialVersionUID = 1L;

	private int cid;
	private String cname;
	
	
	public int getCid() {
		return cid;
	}
	public void setCid(int cid) {
		this.cid = cid;
	}
	public String getCname() {
		return cname;
	}
	public void setCname(String cname) {
		this.cname = cname;
	}
	
	public Class() {
		// TODO Auto-generated constructor stub
	}
	public Class(int cid, String cname) {
		this.cid = cid;
		this.cname = cname;
	}
	@Override
	public String toString() {
		return "Class [cid=" + cid + ", cname=" + cname + "]";
	}
	
	
	
}

teacher类(教师类):

package com.ruojuan.entity;

import java.io.Serializable;

public class Theaher implements Serializable{
	
	private static final long serialVersionUID = 1L;
	
	private int tid;
	private String tname;

	
	public int getTid() {
		return tid;
	}
	public void setTid(int tid) {
		this.tid = tid;
	}
	public String getTname() {
		return tname;
	}
	public void setTname(String tname) {
		this.tname = tname;
	}
	public Theaher() {
		// TODO Auto-generated constructor stub
	}

	public Theaher(int tid, String tname) {
		this.tid = tid;
		this.tname = tname;
	}
	
	
	@Override
	public String toString() {
		return "Theaher [tid=" + tid + ", tname=" + tname + "]";
	}
	
	

	
	
	
	
}

 hobby类(爱好类):

package com.ruojuan.entity;

import java.io.Serializable;

/**
 * 爱好类
 * @author liuruojuan
 *
 * 时间:2022年6月18日下午7:35:50
 */
public class Hobby implements Serializable{

	private static final long serialVersionUID = 1L;
	
	private int hid;
	private String hname;
	public int getHid() {
		return hid;
	}
	public void setHid(int hid) {
		this.hid = hid;
	}
	public String getHname() {
		return hname;
	}
	public void setHname(String hname) {
		this.hname = hname;
	}

	public Hobby() {
		// TODO Auto-generated constructor stub
	}
	public Hobby(int hid, String hname) {
		this.hid = hid;
		this.hname = hname;
	}
	@Override
	public String toString() {
		return "Hobby [hid=" + hid + ", hname=" + hname + "]";
	}
	
	
	
	
}

student类(学生类):

package com.ruojuan.entity;

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

/**
 * 学生类
 * @author liuruojuan
 *
 * 时间:2022年6月18日下午7:36:57
 */
public class Student implements Serializable{
	
	private static final long serialVersionUID = 1L;
	
	private int sid;
	private String sname;
	private Class 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 Class getCl() {
		return cl;
	}
	public void setCl(Class 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, Class 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, Class 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 + "]";
	}
	
	
	
	
	
	
	
	
}

                ③数据库访问层  dao

        1.idao

Class类(班级类):

package com.ruojuan.dao;

import java.util.List;

import com.ruojuan.entity.Class;


public interface IClDao {

	/**
	 * 爱好集合
	 * @return
	 */
	public List<Class> getAll();
	
	/**
	 * 查询单个
	 * @param cid 班级编号
	 * @return 返回对象
	 */
	public Class getdg(int cid);

}

teacher类(教师类):

package com.ruojuan.dao;

import java.util.List;

import com.ruojuan.entity.Theaher;

public interface IThDao {
	/**
	 * 教员集合
	 * @return
	 */
	public List<Theaher> getAll();

	/**
	 * 查看单个
	 * @param tid
	 * @return
	 */
	public Theaher getdg(int tid);
	
	
}

hobby类(爱好类):

package com.ruojuan.dao;

import java.util.List;

import com.ruojuan.entity.Hobby;

public interface IHyDao {

	/**
	 * 爱好集合
	 * @return
	 */
	public List<Hobby> getAll();
	
	/**
	 * 爱好查询单个
	 * @param hid 爱好编号
	 * @return 返回爱好对象
	 */
	public Hobby getdg(int hid);
}

student类(学生类):

package com.ruojuan.dao;

import java.util.List;

import com.ruojuan.entity.Class;
import com.ruojuan.entity.Hobby;
import com.ruojuan.entity.Student;
import com.ruojuan.entity.Theaher;

public interface IStuDao {
	
	/**
	 * 学生集合
	 * @return
	 */
	public List<Student> getAll(String cid,String tid,String hid,int pageIndex,int pageSize);
	
	
	/**
	 * 查询单个学生
	 * @param sid 学生编号
	 * @return 返回单个学生
	 */
	public Student getdg(int sid);
	
	
	/**
	 * 增加
	 * @param stu
	 * @return
	 */
	public int addStu(String sname, Class cl, Theaher th, List<Hobby> hy);
	
	
	/**
	 * 删除
	 * @param sid 删除id
	 * @return  返回行数
	 */
	public int delStu(int sid);
	
	/**
	 * 修改
	 * @param sid 学生id
	 * @param sname 学生姓名
	 * @param cl  班级
	 * @param th  教员
	 * @param hy  爱好
	 * @return  返回执行行数
	 */
	public int updStu(int sid,String sname, Class cl, Theaher th, List<Hobby> hy);
	
	
	/**
	 * 总数
	 * @return
	 */
	public int count(String cid,String tid,String hid);
	
	
}

        2.dao方法

Class类(班级类):

package com.ruojuan.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.ruojuan.entity.Class;
import com.ruojuan.util.DBHelper;

public class ClDao implements IClDao{

	//扩大作用域
	Connection conn = null;
	Statement stmt = null;
	ResultSet rs = null;

	
	@Override
	public List<Class> getAll() {
		List<Class> ls = new ArrayList<Class>();
		try {
			//连接数据库
			conn = DBHelper.getConnection();
			//定义sql语句
			String sql = "select * from tb_class";
			//执行sql语句
			stmt = conn.prepareStatement(sql);
			//获得结果集
			rs = stmt.executeQuery(sql);
			//遍历结果集
			while(rs.next()) {
				//实例化
				Class cl = new Class(rs.getInt(1),rs.getString(2));
				//加到集合中
				ls.add(cl);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DBHelper.close(conn, stmt, rs);
		}
		return ls;

	}


	@Override
	public Class getdg(int cid) {
		Class cl = new Class();
		try {
			//连接数据库
			conn = DBHelper.getConnection();
			//定义sql语句
			String sql = "select * from tb_class where cid="+cid+"";
			//执行sql语句
			stmt = conn.prepareStatement(sql);
			//获得结果集
			rs = stmt.executeQuery(sql);
			//遍历结果集
			while(rs.next()) {
				//实例化
				cl = new Class(rs.getInt(1),rs.getString(2));
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DBHelper.close(conn, stmt, rs);
		}
		return cl;

	}
	
//	public static void main(String[] args) {
//		System.out.println(new ClDao().getdg(1));
//	}

}

teacher类(教师类):

package com.ruojuan.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.ruojuan.entity.Theaher;
import com.ruojuan.util.DBHelper;

public class ThDao implements IThDao{

	//扩大作用域
	Connection conn = null;
	Statement stmt = null;
	ResultSet rs = null;

	
	@Override
	public List<Theaher> getAll() {
		List<Theaher> ls = new ArrayList<Theaher>();
		try {
			//连接数据库
			conn = DBHelper.getConnection();
			//定义sql语句
			String sql = "select * from tb_theacher";
			//执行sql语句
			stmt = conn.prepareStatement(sql);
			//获得结果集
			rs = stmt.executeQuery(sql);
			//遍历结果集
			while(rs.next()) {
				//实例化
				Theaher th = new Theaher(rs.getInt(1),rs.getString(2));
				//加到集合中
				ls.add(th);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DBHelper.close(conn, stmt, rs);
		}
		return ls;

	}


	@Override
	public Theaher getdg(int tid) {
		//教师
		Theaher th = new Theaher();
		try {
			//连接数据库
			conn = DBHelper.getConnection();
			//定义sql语句
			String sql = "select* from tb_theacher where tid="+tid+"";
			//执行sql语句
			stmt = conn.prepareStatement(sql);
			//获得结果集
			rs = stmt.executeQuery(sql);
			//遍历结果集
			while(rs.next()) {
				//实例化
				th = new Theaher(rs.getInt("tid"),rs.getString("tname"));
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DBHelper.close(conn, stmt, rs);
		}
		return th;

	}
	
//	public static void main(String[] args) {
//		System.out.println(new ThDao().getdg(5));
//	}


}

hobby类(爱好类):

package com.ruojuan.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.ruojuan.entity.Hobby;
import com.ruojuan.util.DBHelper;

public class HyDao implements IHyDao{

	//扩大作用域
	Connection conn = null;
	Statement stmt = null;
	ResultSet rs = null;

	
	@Override
	public List<Hobby> getAll() {
		List<Hobby> ls = new ArrayList<Hobby>();
		try {
			//连接数据库
			conn = DBHelper.getConnection();
			//定义sql语句
			String sql = "select * from tb_hobby";
			//执行sql语句
			stmt = conn.prepareStatement(sql);
			//获得结果集
			rs = stmt.executeQuery(sql);
			//遍历结果集
			while(rs.next()) {
				//实例化
				Hobby hy = new Hobby(rs.getInt(1),rs.getString(2));
				//加到集合中
				ls.add(hy);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DBHelper.close(conn, stmt, rs);
		}
		return ls;
	}


	@Override
	public Hobby getdg(int hid) {
		Hobby  hy = new Hobby();
		try {
			//连接数据库
			conn = DBHelper.getConnection();
			//定义sql语句
			String sql = "select * from tb_hobby where hid="+hid+"";
			//执行sql语句
			stmt = conn.prepareStatement(sql);
			//获得结果集
			rs = stmt.executeQuery(sql);
			//遍历结果集
			while(rs.next()) {
				//实例化
				hy = new Hobby(rs.getInt(1),rs.getString(2));
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DBHelper.close(conn, stmt, rs);
		}
		return hy;
	}

	
}

student类(学生类):

package com.ruojuan.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.sql.Statement;

import com.ruojuan.biz.HyBiz;
import com.ruojuan.biz.IHyBiz;
import com.ruojuan.entity.Class;
import com.ruojuan.entity.Hobby;
import com.ruojuan.entity.Student;
import com.ruojuan.entity.Theaher;
import com.ruojuan.util.DBHelper;

public class StuDao implements IStuDao{
	
	//扩大作用域
	Connection conn = null;
	Statement stmt = null;
	ResultSet rs = null;
	PreparedStatement ps = null;
	
	//爱好
	IHyBiz ihb = new HyBiz();

	@Override
	public List<Student> getAll(String cid,String tid,String hid,int pageIndex,int pageSize) {
		int a = (pageIndex-1)*pageSize;
		List<Student> ls = new ArrayList<Student>();
		try {
			//连接数据库
			conn = DBHelper.getConnection();
			//定义sql语句
			String sql = "select * from (\r\n" + 
					"select * from (\r\n" + 
					"select * from (\r\n" + 
					"select *  from (\r\n" + 
					"select a.*,b.hname,c.cname,d.tname from tb_stu a,tb_hobby b,tb_class c,tb_theacher d where a.cid=c.cid and a.tid=d.tid and a.hid = b.hid\r\n" + 
					")q  "+cid+"\r\n" + 
					")w "+tid+"\r\n" + 
					")e "+hid+"\r\n" + 
					")r limit "+a+","+pageSize+"";
//			System.out.println(sql);
			//执行sql语句
			stmt = conn.prepareStatement(sql);
			//获得结果集
			rs = stmt.executeQuery(sql);
			//遍历结果及
			while(rs.next()) {
				List<Hobby> hy = new ArrayList<>();
				String str = rs.getString("hid");
				String[] split = str.split(" ");
				for (String hids : split) {
					//查询单个
					Hobby hby = ihb.getdg(Integer.parseInt(hids));
					hy.add(hby);
				}
				
				//班级
				Class cl = new Class(rs.getInt("cid"),rs.getString("cname"));
				//教员
				Theaher th = new Theaher(rs.getInt("tid"),rs.getString("tname"));
				//学生
				Student stu = new Student(rs.getInt("sid"),rs.getString("sname"),cl,th,hy);
				//加到集合中
				ls.add(stu);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DBHelper.close(conn, stmt, rs);
		}
		return ls;
	}
	
	
	
	@Override
	public Student getdg(int sid) {
		Student stu = new Student();
		try {
			//连接数据库
			conn = DBHelper.getConnection();
			//定义sql语句
			String sql = "select * from (\r\n" + 
					"select a.*,b.hname,c.cname,d.tname from tb_stu a,tb_hobby b,tb_class c,tb_theacher d where a.cid=c.cname and a.tid=d.tid and a.hid = b.hid ) e where e.sid="+sid+"";
			//执行sql语句
			stmt = conn.prepareStatement(sql);
			//获得结果集
			rs = stmt.executeQuery(sql);
			//遍历结果及
			while(rs.next()) {
				List<Hobby> hy = new ArrayList<>();
				String str = rs.getString("hid");
				String[] split = str.split(" ");
				for (String hid : split) {
					//查询单个
					Hobby hby = ihb.getdg(Integer.parseInt(hid));
					hy.add(hby);
				}
				//班级
				Class cl = new Class(rs.getInt("cid"),rs.getString("cname"));
				//教员
				Theaher th = new Theaher(rs.getInt("tid"),rs.getString("tname"));
				//学生
				stu = new Student(rs.getInt("sid"),rs.getString("sname"),cl,th,hy);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DBHelper.close(conn, stmt, rs);
		}
		return stu;
	}



	@Override
	public int addStu(String sname, Class cl, Theaher th, List<Hobby> hy) {
		String hh = "";
		for (int i = 0; i < hy.size(); i++) {
			hh+=hy.get(i).getHid()+" ";
		}
		int n = 0;
		try {
			//连接数据库
			conn = DBHelper.getConnection();
			//定义sql语句
			String sql = "insert into tb_stu(sname,cid,tid,hid) values('"+sname+"',"+cl.getCid()+","+th.getTid()+",'"+hh+"')";
			//执行sql语句
			stmt = conn.prepareStatement(sql);
			//返回执行的行数
			n = stmt.executeUpdate(sql);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DBHelper.close(conn, stmt, rs,ps);
		}
		return n;
	}



	@Override
	public int delStu(int sid) {
		int n = 0;
		try {
			//连接数据库
			conn = DBHelper.getConnection();
			//定义sql语句
			String sql = "delete from tb_stu where sid="+sid+"";
			//执行sql语句
			stmt = conn.prepareStatement(sql);
			//返回执行的行数
			n = stmt.executeUpdate(sql);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DBHelper.close(conn, stmt, rs, ps);
		}
		return n;
	}



	@Override
	public int updStu(int sid, String sname, Class cl, Theaher th, List<Hobby> hy) {
		int n = 0;
		String hh = "";
		for (int i = 0; i < hy.size(); i++) {
			hh+=hy.get(i).getHid()+" ";
		}
		try {
			//连接数据库
			conn = DBHelper.getConnection();
			//定义sql语句
			String sql = "update tb_stu set sname='"+sname+"',cid="+cl.getCid()+",tid="+th.getTid()+",hid='"+hh+"' where sid="+sid+"";
			//执行sql语句
			stmt = conn.prepareStatement(sql);
			
			//返回执行的行数
			n = stmt.executeUpdate(sql);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DBHelper.close(conn, stmt, rs, ps);
		}
		return n;

	}



	@Override
	public int count(String cid,String tid,String hid) {
		int n = 0;
		try {
			//连接数据库
			conn = DBHelper.getConnection();
			//定义sql语句
			String sql = "select count(*) from (\r\n" + 
					"select * from (\r\n" + 
					"select * from (\r\n" + 
					"select *  from (\r\n" + 
					"select a.*,b.hname,c.cname,d.tname from tb_stu a,tb_hobby b,tb_class c,tb_theacher d where a.cid=c.cid and a.tid=d.tid and a.hid = b.hid\r\n" + 
					")q  "+cid+" \r\n" + 
					")w  "+tid+" \r\n" + 
					")e  "+hid+" \r\n" + 
					")t";
//			System.out.println(sql);
			//执行sql语句
			stmt = conn.prepareStatement(sql);
			//结果集
			rs = stmt.executeQuery(sql);
			if(rs.next()) {
				//返回执行的行数
				n = rs.getInt(1);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DBHelper.close(conn, stmt, rs, ps);;
		}
		return n;
	}


	
}

                ④业务逻辑层  biz

1.ibiz

Class类(班级类):

package com.ruojuan.biz;

import java.util.List;

import com.ruojuan.entity.Class;

public interface IClBiz {

	/**
	 * 爱好集合
	 * @return
	 */
	public List<Class> getAll();

	/**
	 * 查询单个
	 * @param cid 班级编号
	 * @return 返回对象
	 */
	public Class getdg(int cid);

}

teacher类(教师类):

package com.ruojuan.biz;

import java.util.List;

import com.ruojuan.entity.Theaher;

public interface IThBiz {

	/**
	 * 教员集合
	 * @return
	 */
	public List<Theaher> getAll();

	
	/**
	 * 查看单个
	 * @param tid
	 * @return
	 */
	public Theaher getdg(int tid);

	
}

hobby类(爱好类):

package com.ruojuan.biz;

import java.util.List;

import com.ruojuan.entity.Hobby;

public interface IHyBiz {

	/**
	 * 爱好集合
	 * @return
	 */
	public List<Hobby> getAll();

	
	/**
	 * 爱好查询单个
	 * @param hid 爱好编号
	 * @return 返回爱好对象
	 */
	public Hobby getdg(int hid);
}

student类(学生类):

package com.ruojuan.biz;

import java.util.List;

import com.ruojuan.entity.Class;
import com.ruojuan.entity.Hobby;
import com.ruojuan.entity.Student;
import com.ruojuan.entity.Theaher;

public interface IStuBiz {

	/**
	 * 学生集合
	 * @return
	 */
	public List<Student> getAll(String cid,String tid,String hid,int pageIndex,int pageSize);

	/**
	 * 查询单个学生
	 * @param sid 学生编号
	 * @return 返回单个学生
	 */
	public Student getdg(int sid);

	
	/**
	 * 增加
	 * @param stu
	 * @return
	 */
	public int addStu(String sname, Class cl, Theaher th, List<Hobby> hy);
	
	
	/**
	 * 删除
	 * @param sid 删除id
	 * @return  返回行数
	 */
	public int delStu(int sid);
	
	/**
	 * 修改
	 * @param sid 学生id
	 * @param sname 学生姓名
	 * @param cl  班级
	 * @param th  教员
	 * @param hy  爱好
	 * @return  返回执行行数
	 */
	public int updStu(int sid,String sname, Class cl, Theaher th, List<Hobby> hy);
	
	
	/**
	 * 总数
	 * @return
	 */
	public int count(String cid,String tid,String hid);


	
}

2.biz

Class类(班级类):

package com.ruojuan.biz;

import java.util.List;

import com.ruojuan.dao.ClDao;
import com.ruojuan.dao.IClDao;
import com.ruojuan.entity.Class;

public class ClBiz implements IClBiz{

	//访问数据库
	IClDao icd = new ClDao();
	
	@Override
	public List<Class> getAll() {
		return icd.getAll();
	}

	@Override
	public Class getdg(int cid) {
		return icd.getdg(cid);
	}

	
	
}

teacher类(教师类):

package com.ruojuan.biz;

import java.util.List;

import com.ruojuan.dao.IThDao;
import com.ruojuan.dao.ThDao;
import com.ruojuan.entity.Theaher;

public class ThBiz implements IThBiz{

	//访问数据库
	IThDao itd = new ThDao();
	
	@Override
	public List<Theaher> getAll() {
		return itd.getAll();
	}

	@Override
	public Theaher getdg(int tid) {
		return itd.getdg(tid);
	}

	
	
	
}

hobby类(爱好类):

package com.ruojuan.biz;

import java.util.List;

import com.ruojuan.dao.HyDao;
import com.ruojuan.dao.IHyDao;
import com.ruojuan.entity.Hobby;

public class HyBiz implements IHyBiz{

	//访问数据库
	IHyDao ihd = new HyDao();
	
	@Override
	public List<Hobby> getAll() {
		return ihd.getAll();
	}

	@Override
	public Hobby getdg(int hid) {
		return ihd.getdg(hid);
	}

}

student类(学生类):

package com.ruojuan.biz;

import java.util.List;

import com.ruojuan.dao.IStuDao;
import com.ruojuan.dao.StuDao;
import com.ruojuan.entity.Class;
import com.ruojuan.entity.Hobby;
import com.ruojuan.entity.Student;
import com.ruojuan.entity.Theaher;

public class StuBiz implements IStuBiz {

	//数据库访问层
	IStuDao isd = new StuDao();
	
	@Override
	public List<Student> getAll(String cid,String tid,String hid,int pageIndex,int pageSize) {
		return isd.getAll(cid, tid, hid, pageIndex, pageSize);
	}

	@Override
	public Student getdg(int sid) {
		return isd.getdg(sid);
	}

	@Override
	public int addStu(String sname, Class cl, Theaher th, List<Hobby> hy) {
		return isd.addStu(sname, cl, th, hy);
	}

	@Override
	public int delStu(int sid) {
		return isd.delStu(sid);
	}

	@Override
	public int updStu(int sid, String sname, Class cl, Theaher th, List<Hobby> hy) {
		return isd.updStu(sid, sname, cl, th, hy);
	}

	@Override
	public int count(String cid,String tid,String hid) {
		return isd.count(cid, tid, hid);
	}
	
}

                ⑤ 控制层 servlet

1.主界面梆值(模糊查询,分页):

package com.ruojuan.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruojuan.biz.ClBiz;
import com.ruojuan.biz.HyBiz;
import com.ruojuan.biz.IClBiz;
import com.ruojuan.biz.IHyBiz;
import com.ruojuan.biz.IStuBiz;
import com.ruojuan.biz.IThBiz;
import com.ruojuan.biz.StuBiz;
import com.ruojuan.biz.ThBiz;
import com.ruojuan.entity.Class;
import com.ruojuan.entity.Hobby;
import com.ruojuan.entity.Student;
import com.ruojuan.entity.Theaher;

/**
 * Servlet implementation class IndexServlet
 */
@WebServlet("/IndexServlet")
public class IndexServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//设置编码方式
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=UTF-8");
		
		//扩大作用域
		int pageIndex = 1;
		int pageSize = 2;
		//接收表单
		String cid = request.getParameter("cid");
		if(cid==null) {
			cid="";
		}
		
		String tid= request.getParameter("tid");
		if(tid==null) {
			tid="";
		}
		String[] hids = request.getParameterValues("hid");
		String hid = "";
		String hidd ="";//用来拼接
		if(hids==null) {
			hidd=" ";
			hid="";
		}
		else {
			for (String str : hids) {
				hidd+=str+" ";//用空格进行隔开
				hid= " where hid like '%"+hidd+"%' ";
			}
		}
		
		String pid = request.getParameter("pid");
		if(pid!=null){//说明点了x页
			pageIndex = Integer.parseInt(pid);
		}
		
		String gid = request.getParameter("gid");
//		System.out.println("ska:"+gid);
		if(gid==null) {
			gid="";
		}
		else if(gid=="") {
			gid="";
		}
		else{
			pageIndex = Integer.parseInt(gid);
		}
		
		
		//业务逻辑层
		IStuBiz isb = new StuBiz();
		IHyBiz ihb = new HyBiz();//爱好
		IThBiz itb = new ThBiz();//教员
		IClBiz icb = new ClBiz();//班级

		//调用查询全部的方法
		List<Student> stu = isb.getAll(cid, tid,hid, pageIndex, pageSize);
		List<Hobby> hobby12 = ihb.getAll();
		List<Theaher> theaher12 = itb.getAll();
		List<Class> clas12 = icb.getAll();
		int count = isb.count(cid, tid, hid);
		
		int pagecount=0;
		if(count%pageSize==1) {
			pagecount=count/pageSize+1;
		}
		else {
			pagecount=count/pageSize;
		}
		
		if(stu.size()!=0) {
			//加到集合中
			request.setAttribute("stu", stu);
			request.setAttribute("hobby12", hobby12);
			request.setAttribute("theaher12", theaher12);
			request.setAttribute("clas12", clas12);
			request.setAttribute("count", count);
			request.setAttribute("pagecount", pagecount);
			request.setAttribute("pageIndex", pageIndex);
			
			//转发
			request.getRequestDispatcher("index.jsp").forward(request, response);
		}
		else {
			System.out.println("集合为空");
		}
		
		
	}

}

2.增加界面前的:

package com.ruojuan.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruojuan.biz.ClBiz;
import com.ruojuan.biz.HyBiz;
import com.ruojuan.biz.IClBiz;
import com.ruojuan.biz.IHyBiz;
import com.ruojuan.biz.IThBiz;
import com.ruojuan.biz.ThBiz;
import com.ruojuan.entity.Class;
import com.ruojuan.entity.Hobby;
import com.ruojuan.entity.Theaher;

/**
 * Servlet implementation class FoundServlet
 */
@WebServlet("/FoundServlet")
public class FoundServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//设置编码方式
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=UTF-8");

		//业务逻辑层
		IHyBiz ihb = new HyBiz();//爱好
		IThBiz itb = new ThBiz();//教员
		IClBiz icb = new ClBiz();//班级
		
		//调用查询全部的方法
		List<Hobby> hobby = ihb.getAll();
		List<Theaher> theaher = itb.getAll();
		List<Class> clas = icb.getAll();
		
		//判断
		if(hobby!=null&&theaher!=null&&clas!=null) {
			//加到集合中
			request.setAttribute("hobby", hobby);
			request.setAttribute("theaher", theaher);
			request.setAttribute("clas", clas);
			//转发
			request.getRequestDispatcher("add.jsp").forward(request, response);
		}
		else {
			System.out.println("集合为空");
		}
		
	}

}

3.增加功能:

package com.ruojuan.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruojuan.biz.ClBiz;
import com.ruojuan.biz.HyBiz;
import com.ruojuan.biz.IClBiz;
import com.ruojuan.biz.IHyBiz;
import com.ruojuan.biz.IStuBiz;
import com.ruojuan.biz.IThBiz;
import com.ruojuan.biz.StuBiz;
import com.ruojuan.biz.ThBiz;
import com.ruojuan.entity.Class;
import com.ruojuan.entity.Hobby;
import com.ruojuan.entity.Student;
import com.ruojuan.entity.Theaher;

/**
 * 增加功能
 * @author liuruojuan
 *
 * 时间:2022年6月18日下午7:52:20
 */
@WebServlet("/AddServlet")
public class AddServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//设置编码方式
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=UTF-8");

		//获取表单提交过来的值
		String sname = request.getParameter("sname");
		String tid = request.getParameter("tid");
		String cid = request.getParameter("cid");
		String [] hids = request.getParameterValues("hid");
	    String hsy = "";//用来拼接
		for (String str : hids) {
			hsy+=str+" ";//用空格进行隔开
		}
		
		PrintWriter out = response.getWriter();
		
		//业务逻辑层
		IThBiz itb = new ThBiz();
		IClBiz icb = new ClBiz();
		IHyBiz ihb = new HyBiz();
		IStuBiz isb = new StuBiz();
		
		List<Hobby> hy = new ArrayList<>();
		String[] split = hsy.split(" ");
		for (String hid : split) {
			//查询单个
			Hobby hby = ihb.getdg(Integer.parseInt(hid));
			hy.add(hby);
		}
		//教员查询单个
		Theaher th = itb.getdg(Integer.parseInt(tid));
		//班级查询单个
		Class cl = icb.getdg(Integer.parseInt(cid));
		//调用增加的方法
		int n = isb.addStu(sname, cl, th, hy);		
		if(n>0) {
			out.print("<script>alert('增加成功');location.href='index.jsp'</script>");
		}
		else {
			out.print("<script>alert('增加失败');location.href='index.jsp'</script>");
		}
		
	}

}

4.查看功能:

package com.ruojuan.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruojuan.biz.ClBiz;
import com.ruojuan.biz.HyBiz;
import com.ruojuan.biz.IClBiz;
import com.ruojuan.biz.IHyBiz;
import com.ruojuan.biz.IStuBiz;
import com.ruojuan.biz.IThBiz;
import com.ruojuan.biz.StuBiz;
import com.ruojuan.biz.ThBiz;
import com.ruojuan.entity.Class;
import com.ruojuan.entity.Hobby;
import com.ruojuan.entity.Student;
import com.ruojuan.entity.Theaher;

/**
 * 查看功能
 * @author liuruojuan
 *
 * 时间:2022年6月18日下午7:53:22
 */
@WebServlet("/CheckServlet")
public class CheckServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//设置编码方式
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=UTF-8");
		
		//接收表单提交过来的值
		String sid = request.getParameter("sid");

		//业务逻辑层
		IHyBiz ihb = new HyBiz();//爱好
		IThBiz itb = new ThBiz();//教员
		IClBiz icb = new ClBiz();//班级
		IStuBiz isb = new StuBiz();//学生
		
		//调用查询全部的方法
		List<Hobby> hobby2 = ihb.getAll();
		List<Theaher> theaher2 = itb.getAll();
		List<Class> clas2 = icb.getAll();
		Student student2 = isb.getdg(Integer.parseInt(sid));
		List<Hobby> hy = student2.getHy();
		String bb = "";
		for (Hobby hobby : hy) {
			int hid = hobby.getHid();
			bb+=hid+" ";
		}
//		Student student2 = isb.getdg(2);
		//判断
		if(hobby2!=null&&theaher2!=null&&clas2!=null&&student2!=null) {
			//加到集合中
			request.setAttribute("hobby2", hobby2);
			request.setAttribute("theaher2", theaher2);
			request.setAttribute("clas2", clas2);
			request.setAttribute("student2", student2);
			request.setAttribute("bb", bb);
			//转发
			request.getRequestDispatcher("check.jsp").forward(request, response);
		}
		else {
			System.out.println("集合为空");
		}
	}

}

5.修改前功能:

package com.ruojuan.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruojuan.biz.ClBiz;
import com.ruojuan.biz.HyBiz;
import com.ruojuan.biz.IClBiz;
import com.ruojuan.biz.IHyBiz;
import com.ruojuan.biz.IStuBiz;
import com.ruojuan.biz.IThBiz;
import com.ruojuan.biz.StuBiz;
import com.ruojuan.biz.ThBiz;
import com.ruojuan.entity.Class;
import com.ruojuan.entity.Hobby;
import com.ruojuan.entity.Student;
import com.ruojuan.entity.Theaher;

/**
 * 修改前功能
 * @author liuruojuan
 *
 * 时间:2022年6月18日下午7:53:55
 */
@WebServlet("/XgServlet")
public class XgServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//设置编码方式
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=UTF-8");
		
		//接收表单提交过来的值
		String sid = request.getParameter("sid");

		//业务逻辑层
		IHyBiz ihb = new HyBiz();//爱好
		IThBiz itb = new ThBiz();//教员
		IClBiz icb = new ClBiz();//班级
		IStuBiz isb = new StuBiz();//学生
		
		//调用查询全部的方法
		List<Hobby> hobby1 = ihb.getAll();
		List<Theaher> theaher1 = itb.getAll();
		List<Class> clas1 = icb.getAll();
		Student student1 = isb.getdg(Integer.parseInt(sid));
//		Student student1 = isb.getdg(3);
		List<Hobby> hy = student1.getHy();
		String aa = "";
		for (Hobby hobby : hy) {
			int hid = hobby.getHid();
			aa+=hid+" ";
		}
//		System.out.println(aa);
//		Student student1 = isb.getdg(2);
		//判断
		if(hobby1!=null&&theaher1!=null&&clas1!=null&&student1!=null) {
			//加到集合中
			request.setAttribute("hobby1", hobby1);
			request.setAttribute("theaher1", theaher1);
			request.setAttribute("clas1", clas1);
			request.setAttribute("student1", student1);
			request.setAttribute("aa", aa);
			//转发
			request.getRequestDispatcher("update.jsp").forward(request, response);
		}
		else {
			System.out.println("集合为空");
		}
	}

}

6.修改功能:

package com.ruojuan.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruojuan.biz.ClBiz;
import com.ruojuan.biz.HyBiz;
import com.ruojuan.biz.IClBiz;
import com.ruojuan.biz.IHyBiz;
import com.ruojuan.biz.IStuBiz;
import com.ruojuan.biz.IThBiz;
import com.ruojuan.biz.StuBiz;
import com.ruojuan.biz.ThBiz;
import com.ruojuan.entity.Class;
import com.ruojuan.entity.Hobby;
import com.ruojuan.entity.Theaher;

/**
 * 修改功能
 * @author liuruojuan
 *
 * 时间:2022年6月18日下午7:56:05
 */
@WebServlet("/UpdateServlet")
public class UpdateServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//设置编码方式
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=UTF-8");

		
		//获取表单提交过来的值
		String sid = request.getParameter("sid");
		String sname = request.getParameter("sname");
		String tid = request.getParameter("tid");
		String cid = request.getParameter("cid");
		String [] hids = request.getParameterValues("hid");
	    String hsy = "";//用来拼接
		for (String str : hids) {
			hsy+=str+" ";//用空格进行隔开
		}
		
		PrintWriter out = response.getWriter();
		
		//业务逻辑层
		IThBiz itb = new ThBiz();
		IClBiz icb = new ClBiz();
		IHyBiz ihb = new HyBiz();
		IStuBiz isb = new StuBiz();
		
		List<Hobby> hy = new ArrayList<>();
		String[] split = hsy.split(" ");
		for (String hid : split) {
			//查询单个
			Hobby hby = ihb.getdg(Integer.parseInt(hid));
			hy.add(hby);
		}
		//教员查询单个
		Theaher th = itb.getdg(Integer.parseInt(tid));
		//班级查询单个
		Class cl = icb.getdg(Integer.parseInt(cid));
		//调用增加的方法
		int n = isb.updStu(Integer.parseInt(sid), sname, cl, th, hy);
		
		if(n>0) {
			out.print("<script>alert('修改成功');location.href='index.jsp'</script>");
		}
		else {
			out.print("<script>alert('修改失败');location.href='XgServlet?sid="+sid+"'</script>");
		}
	}

}

7.删除功能:

package com.ruojuan.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruojuan.biz.IStuBiz;
import com.ruojuan.biz.StuBiz;

/**
 * 删除功能
 * @author liuruojuan
 *
 * 时间:2022年6月18日下午7:56:42
 */
@WebServlet("/DeleteServlet")
public class DeleteServlet extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//设置编码方式
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=UTF-8");
		//out
		PrintWriter out = response.getWriter();
		
		//获取表单提交过来的值
		String sid = request.getParameter("sid");
		//业务逻辑
		IStuBiz isb = new StuBiz();
		//删除
		int n = isb.delStu(Integer.parseInt(sid));
		//判断
		if(n>0) {
			out.print("<script>alert('删除成功');location.href='index.jsp'</script>");
		}
		else {
			out.print("<script>alert('删除失败');location.href='index.jsp'</script>");
		}
	}

}

二,界面:

                ①主界面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>主界面</title>
</head>

<body>

	<c:if test="${empty stu }">
	 			<jsp:forward page="IndexServlet"></jsp:forward>
	 </c:if>
	<center>
		<h2>主界面</h2>
		<form action="IndexServlet" method="post">
		<table border="1px">
			<tr>
				<td colspan="6px">
					教员:
					<select name="tid">
						<option value=""  >请选择</option>
					<c:forEach items="${theaher12 }" var="t">
						<option value=" where tid='${t.tid }'"  >${t.tname}</option>
					</c:forEach>
					</select>
					班级:
					<select name="cid">
						<option value=""  >请选择</option>
					<c:forEach items="${clas12 }" var="c">
						<option value=" where cid='${c.cid }'"  >${c.cname}</option>
					</c:forEach>
					</select>
					爱好:
					<c:forEach items="${hobby12 }" var="h">
						<input type="checkbox" name="hid" value="${h.hid }"  >${h.hname}
					</c:forEach>
					<input type="submit" value="查询">
					<input type="button" value="增加" onclick="add()">
				</td>
			</tr>
			<tr>
				<td>学生编号</td>
				<td>学生姓名</td>
				<td>学生教员</td>
				<td>所在班级</td>
				<td>学生爱好</td>
				<td>管理操作</td>
			</tr>
			<c:forEach items="${stu}" var="s">
			<tr>
				<td>${s.sid }</td>
				<td>${s.sname}</td>
				<td>${s.th.tname}</td>
				<td>${s.cl.cname}</td>
				<td>
					<c:forEach items="${s.hy}" var="x">
						${x.hname}
					</c:forEach>
				</td> 
				<td>
					<a href="CheckServlet?sid=${s.sid }">查看</a>
					<a href="XgServlet?sid=${s.sid }">修改</a>
					<a  onclick="return confirm('你确定要删除吗?')"  href="DeleteServlet?sid=${s.sid }">删除</a>
				</td>
			</tr>
			</c:forEach>
		</table>
		 <div>
		 	第${pageIndex}页,&nbsp;&nbsp;共${pagecount}页,&nbsp;&nbsp;总记录${count}条
		 	<a href="IndexServlet?pid=1">首页</a>
		 	<a href="IndexServlet?pid=${pageIndex>1?pageIndex-1:1}">上一页</a>
		 	<a>go<input type="text" onblur="go('gid')" style=" width:15px" width="5px" name="gid" id="gid"></a>
		 	<a href="IndexServlet?pid=${pageIndex<pagecount?pageIndex+1:pagecount}">下一页</a>
		 	<a href="IndexServlet?pid=${pagecount}">尾页</a>
		 </div>
		</form>
	</center>
	<script type="text/javascript">
	
	function add() {
		location.href="FoundServlet";
	}
	
	function go(id){
		var aa = document.getElementById(id);
		var bb = aa.value;
		alert(bb);
		if(isNaN(bb)||bb<0){
			alert("请输入正确的数字");
		}
		else{
			location.href="IndexServlet?gid="+bb+"";
		} 
	}
	
	
</script>


</body>
</html>

                ②增加界面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>增加界面</title>
</head>
<body>
	<center>
	<form action="AddServlet" method="post">
		<table>
			<tr>
				<td>学生姓名</td>
				<td><input type="text" name="sname"></td>
			</tr>
			<tr>
				<td>学生教员</td>
				<td>
					<select name="tid">
					<c:forEach items="${theaher }" var="t">
						<option value="${t.tid }">${t.tname }</option>
					</c:forEach>
					</select>
				</td>
			</tr>
			<tr>
				<td>学生班级</td>
				<td>
					<select name="cid">
					<c:forEach items="${clas }" var="c">
						<option value="${c.cid }">${c.cname}</option>
					</c:forEach>
					</select>
				</td>
			</tr>
			<tr>
				<td>学生爱好</td>
				<td>
				<c:forEach items="${hobby }" var="h">
					<input type="checkbox" name="hid" value="${h.hid }">${h.hname }
				</c:forEach>	
				</td>
			</tr>
			
		</table>
		<input type="submit" value="确定">
		<input type="reset" value="清空">
		</form>
		
	</center>
</body>
</html>

                ③修改界面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>修改</title>
</head>
<body>
	<center>
	<form action="UpdateServlet" method="post">
		<table>
			<tr>
				<td>学生编号</td>
				<td><input type="text" name="sid" value="${student1.sid }" readonly="readonly"></td>
			</tr>
			<tr>
				<td>学生姓名</td>
				<td><input type="text" name="sname" value="${student1.sname }" ></td>
			</tr>
			<tr>
				<td>学生教员</td>
				<td>
					<select name="tid">
					<c:forEach items="${theaher1 }" var="t">
						<option value="${t.tid }" <c:if test="${student1.th.tid==t.tid }">selected="selected"</c:if> >${t.tname }</option>
					</c:forEach>
					</select>
				</td>
			</tr>
			 <tr>
				<td>学生班级</td>
				<td>
					<select name="cid">
					<c:forEach items="${clas1 }" var="c">
						<option value="${c.cid }" <c:if test="${student1.cl.cid==c.cid }">selected="selected"</c:if> >${c.cname}</option>
					</c:forEach>
					</select>
				</td>
			</tr>
			<tr>
				<td>学生爱好</td>
				<td>
					<input type="checkbox" name="hid" value="1"  <c:if test="${aa.contains('1 ') }">checked</c:if>>篮球
					<input type="checkbox" name="hid" value="2"  <c:if test="${aa.contains('2 ') }">checked</c:if>>足球
					<input type="checkbox" name="hid" value="3"  <c:if test="${aa.contains('3 ') }">checked</c:if>>唱歌
					<input type="checkbox" name="hid" value="4"  <c:if test="${aa.contains('4 ') }">checked</c:if>>跳舞
				</td>
			</tr>
			
		</table>
		<input type="submit" value="修改">
		<input type="reset" value="清空">
		</form>
		
	</center>
</body>
</html>

                ④查看界面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>查看界面</title>
</head>
<body>
	<center>
	<form action="#" method="post">
		<table>
			<tr>
				<td>学生编号</td>
				<td><input type="text" name="sid" value="${student2.sid }" readonly="readonly"></td>
			</tr>
			<tr>
				<td>学生姓名</td>
				<td><input type="text" name="sname" value="${student2.sname }" readonly="readonly"></td>
			</tr>
			<tr>
				<td>学生教员</td>
				<td>
					<select name="tid">
					<c:forEach items="${theaher2 }" var="t">
						<option value="${t.tid }" <c:if test="${student2.th.tid==t.tid }">selected="selected"</c:if>  disabled="disabled">${t.tname }</option>
					</c:forEach>
					</select>
				</td>
			</tr>
			 <tr>
				<td>学生班级</td>
				<td>
					<select name="cid">
					<c:forEach items="${clas2 }" var="c">
						<option value="${c.cid }" <c:if test="${student2.cl.cid==c.cid }">selected="selected"</c:if>  disabled="disabled">${c.cname}</option>
					</c:forEach>
					</select>
				</td>
			</tr>
			<tr>
				<td>学生爱好</td>
				<td>
					<input type="checkbox" name="hid" value="1"  <c:if test="${bb.contains('1 ') }">checked</c:if>>篮球
					<input type="checkbox" name="hid" value="2"  <c:if test="${bb.contains('2 ') }">checked</c:if>>足球
					<input type="checkbox" name="hid" value="3"  <c:if test="${bb.contains('3 ') }">checked</c:if>>唱歌
					<input type="checkbox" name="hid" value="4"  <c:if test="${bb.contains('4 ') }">checked</c:if>>跳舞
				</td>
				
			</tr>
			
		</table>
		<a href="index.jsp">返回</a>
		</form>
		
	</center>
</body>
</html>

三,功能展示

        ①查看

        ②增加

  

        ③修改

 

 

        ④删除

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值