package top.qaqaq.java.P571;
import java.util.List;
/**
* @author RichieZhang
* @create 2022-10-28 下午 9:10
*
* DAO:data(base) access object
*/
public class DAO <T>{//表的共性操作的DAO
//添加一条记录
public void add(T t){
}
//删除一条记录
public boolean remove(int index){
return false;
}
//修改一条记录
public void update(int index,T t){
}
//查询一条记录
public T getIndex(int index){
return null;
}
//查询多条记录
public List<T> getForList(int index){
return null;
}
//泛型方法
//举例:获取表中一共有多少条记录?获取最大的员工入职时间?
public <E> E getValue(){
return null;
}
}
package top.qaqaq.java.P571;
import org.junit.jupiter.api.Test;
import java.util.List;
/**
* @author RichieZhang
* @create 2022-10-28 下午 9:20
*/
public class DAOTest {
@Test
public void test1(){
CustomerDAO dao1 = new CustomerDAO();
dao1.add(new Customer());
List<Customer> list = dao1.getForList(10);
StudentDAO dao2 = new StudentDAO();
Student student = dao2.getIndex(1);
}
}
package top.qaqaq.java.P571;
/**
* @author RichieZhang
* @create 2022-10-28 下午 9:15
*/
public class Customer { //此类对应数据库中的customers表
}
package top.qaqaq.java.P571;
/**
* @author RichieZhang
* @create 2022-10-28 下午 9:16
*/
public class CustomerDAO extends DAO<Customer>{//只能操作某一个表的DAO
}
package top.qaqaq.java.P571;
/**
* @author RichieZhang
* @create 2022-10-28 下午 9:24
*/
public class Student {
}
package top.qaqaq.java.P571;
/**
* @author RichieZhang
* @create 2022-10-28 下午 9:24
*/
public class StudentDAO extends DAO<Student> {//只能操作某一个表的DAO
}