package com.atguigu.java2;
import java.util.List;
/**
* @author Dxkstart
* @create 2021-05-28 10:28
*
*
*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 getIntex(int index){
return null;
}
//查询多条记录
public List<T> getForList(int index){
return null;
}
//泛型方法
//举例:获取表中一共有多少条记录?获取最大的员工入职时间?
public <E> E getValue(){
return null;
}
}
package com.atguigu.java2;
import org.junit.Test;
import java.util.List;
/**
* @author Dxkstart
* @create 2021-05-28 10:41
*/
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.getIntex(1);
}
}
package com.atguigu.java2;
/**
* @author Dxkstart
* @create 2021-05-28 10:34
*/
public class Customer {//此类对应数据库中的customers表
}
package com.atguigu.java2;
/**
* @author Dxkstart
* @create 2021-05-28 10:36
*/
public class CustomerDAO extends DAO <Customer>{//只能操作Customer表的DAO
}
package com.atguigu.java2;
/**
* @author Dxkstart
* @create 2021-05-28 10:45
*/
public class Student {
}
package com.atguigu.java2;
/**
* @author Dxkstart
* @create 2021-05-28 10:45
*/
public class StudentDAO extends DAO<Student>{//只能操作Student表的DAO
}