1. package com.atguigu.java2;
    2. import java.util.List;
    3. /**
    4. * @author Dxkstart
    5. * @create 2021-05-28 10:28
    6. *
    7. *
    8. *DAO:data(base) access object ---数据访问对象
    9. *
    10. */
    11. public class DAO <T>{//操作数据库中所有表的一些通用操作的DAO
    12. //添加一条记录
    13. public void add(T t){
    14. }
    15. //删除一条记录
    16. public boolean remove(int index){
    17. return false;
    18. }
    19. //修改一条记录
    20. public void update(int index,T t){
    21. }
    22. //查询一条记录
    23. public T getIntex(int index){
    24. return null;
    25. }
    26. //查询多条记录
    27. public List<T> getForList(int index){
    28. return null;
    29. }
    30. //泛型方法
    31. //举例:获取表中一共有多少条记录?获取最大的员工入职时间?
    32. public <E> E getValue(){
    33. return null;
    34. }
    35. }
    1. package com.atguigu.java2;
    2. import org.junit.Test;
    3. import java.util.List;
    4. /**
    5. * @author Dxkstart
    6. * @create 2021-05-28 10:41
    7. */
    8. public class DAOTest {
    9. @Test
    10. public void test1(){
    11. CustomerDAO dao1 = new CustomerDAO();
    12. dao1.add(new Customer());
    13. List<Customer> list = dao1.getForList(10);
    14. StudentDAO dao2 = new StudentDAO();
    15. Student student = dao2.getIntex(1);
    16. }
    17. }
    1. package com.atguigu.java2;
    2. /**
    3. * @author Dxkstart
    4. * @create 2021-05-28 10:34
    5. */
    6. public class Customer {//此类对应数据库中的customers表
    7. }
    1. package com.atguigu.java2;
    2. /**
    3. * @author Dxkstart
    4. * @create 2021-05-28 10:36
    5. */
    6. public class CustomerDAO extends DAO <Customer>{//只能操作Customer表的DAO
    7. }
    1. package com.atguigu.java2;
    2. /**
    3. * @author Dxkstart
    4. * @create 2021-05-28 10:45
    5. */
    6. public class Student {
    7. }
    1. package com.atguigu.java2;
    2. /**
    3. * @author Dxkstart
    4. * @create 2021-05-28 10:45
    5. */
    6. public class StudentDAO extends DAO<Student>{//只能操作Student表的DAO
    7. }