尚硅谷之JDBC

1.5 继承BasicDAO的后的DAO实现类

DepartmentDAO实现类

package com.atguigu.dao.impl.basic;

 

import java.util.ArrayList;

import java.util.List;

 

import com.atguigu.bean.Department;

import com.atguigu.dao.DepartmentDAO;

import com.atguigu.dao.impl.BasicDAOImpl;

 

public class DepartmentDAOImplBasic extends BasicDAOImpl<Department> implements DepartmentDAO{

 

    @Override

    public void addDepartment(Department department) throws Exception {

        String sql = "INSERT INTO t_department(did,dname,description) VALUES(NULL,?,?)";

        update(sql, department.getName(),department.getDescription());

    }

 

    @Override

    public void updateDepartment(Department department) throws Exception {

        String sql = "UPDATE t_department SET dname = ?,description = ? WHERE did = ?";

        update(sql, department.getName(),department.getDescription(),department.getId());

    }

 

    @Override

    public void deleteById(String did) throws Exception {

        String sql = "DELETE FROM t_department WHERE did = ?";

        update(sql, did);

    }

 

    @Override

    public Department getById(String did) throws Exception {

        String sql = "SELECT did as id,dname as name,description FROM t_department WHERE did = ?";

        Department department = get(sql, did);

        return department;

    }

 

    @Override

    public List<Department> getAll() throws Exception {

        String sql = "SELECT did as id,dname as name,description FROM t_department";

        ArrayList<Department> list = getList(sql);

        return list;

    }

 

}