Java课程设计---浏览学生(实现根据姓名查询)

1、修改窗口

2、在StudentDao中增加根据姓名查找的方法

package com.student.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.student.model.Student;
import com.student.util.DbUtil;

/*
 * 项目名称: 
 * 
 * 文件名称为:StudentDao.java
 * 文件创建人:daxiang
 * 
 * @author daxiang
 * @version 
 * @time  2018年6月20日 上午8:10:50
 * @copyright daxiang
 */
public class StudentDao {

	public List<Student> getStudent(String name)throws SQLException{
		DbUtil dbUtil = new DbUtil();
		String sql="select * from tb_student where name LIKE '"+name+"%'";
		System.out.println(sql);
		List<Student> list = new ArrayList<Student>();
		ResultSet rs=dbUtil.executeQuery(sql);
		while(rs.next()){
			Student student = new Student();
			student.setId(rs.getInt("id"));
			student.setName(rs.getString("name"));
			student.setSex(rs.getString("sex"));
			student.setSno(rs.getString("sno"));
			student.setClassName(rs.getString("classname"));
			list.add(student);
		}
		return list;
	}
}

  

3、在StudentService中增加服务

4、将窗口和服务绑定

猜你喜欢

转载自www.cnblogs.com/daxiang2008/p/9212025.html