What are the DAO, DTO and Service layers in Spring Framework?

后端 未结 5 1839
陌清茗
陌清茗 2020-12-12 10:29

I am writing RESTful services using spring and hibernate. I read many resource in internet, but they did not clarify my doubts. Please explain me in details what are DAO

5条回答
  •  萌比男神i
    2020-12-12 11:15

    DAO - Data Access Object:

    An object that provides a common interface to perform all database operations like persistence mechanism.

    public interface GenericDao {
      public T find(Class entityClass, Object id);
      public void save(T entity);
      public T update(T entity);
      public void delete(T entity);
      public List findAll(Class entityClass);
    }
    

    See this example : Spring – DAO and Service layer

    DTO - Data Transfer Object:

    An object that carries data between processes in order to reduce the number of method calls means you combine more than one POJO entities in service layer.

    For example a GET request /rest/customer/101/orders is to retrieve all the orders for customer id 101 along with customer details hence you need combine entity Customer and entity Orders with details.

提交回复
热议问题