Java中的数据访问对象(DAO) [英] Data access object (DAO) in Java

查看:98
本文介绍了Java中的数据访问对象(DAO)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读一份文件,我遇到了一个名为 DAO 的术语。我发现它是一个数据访问对象。有人可以解释一下这究竟是什么吗?

I was going through a document and I came across a term called DAO. I found out that it is a Data Access Object. Can someone please explain me what this actually is?

我知道它是某种用于访问来自不同类型数据源的数据的接口,在我的这个小研究中,我碰到了一个叫做数据的概念源或数据源对象,事情在我的脑海中搞砸了。

I know that it is some kind of an interface for accessing data from different types of sources, in the middle of this little research of mine I bumped into a concept called data source or data source object, and things got messed up in my mind.

我真的想知道 DAO 在编程方面的用途。怎么用?任何从基本内容解释这个概念的页面的链接也很受欢迎。

I really want to know what a DAO is programmatically in terms of where it is used. How it is used? Any links to pages that explain this concept from the very basic stuff is also appreciated.

推荐答案

数据访问对象基本上是一个对象或者提供对底层数据库或任何其他持久性存储的访问的接口。

The Data Access Object is basically an object or an interface that provides access to an underlying database or any other persistence storage.

该定义来自:
http://en.wikipedia .org / wiki / Data_access_object

此处还查看序列图:
http://www.oracle.com/technetwork/java/dataaccessobject-138824.html

也许一个简单的例子可以帮助你理解这个概念:

Maybe a simple example can help you understand the concept:

假设我们有一个代表员工的实体:

Let's say we have an entity to represent an employee:

public class Employee {

    private int id;
    private String name;


    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

}

员工实体将持续存入数据库中对应的 Employee 表。
处理操作员工实体所需的数据库操作的简单DAO接口如下:

The employee entities will be persisted into a corresponding Employee table in a database. A simple DAO interface to handle the database operation required to manipulate an employee entity will be like:

interface EmployeeDAO {

    List<Employee> findAll();
    List<Employee> findById();
    List<Employee> findByName();
    boolean insertEmployee(Employee employee);
    boolean updateEmployee(Employee employee);
    boolean deleteEmployee(Employee employee);

}

接下来我们必须为该接口提供具体实现处理SQL服务器,另一个处理平面文件等。

Next we have to provide a concrete implementation for that interface to deal with SQL server, and another to deal with flat files, etc.

这篇关于Java中的数据访问对象(DAO)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆