简体   繁体   English

功能的哪一部分应该放在DAO层中,哪部分放在服务层中

[英]which part of function should go in DAO layer and which in service layer

Initially I had the all the DAO in service layer. 最初我在服务层有所有DAO。 But to go the proper way i am making the separate DAO layer but i am little bit confused as to which things come in DAO and which in service layer 但是要以正确的方式进行单独的DAO层,但我对DAO中的哪些内容以及服务层中的哪些内容感到困惑

I had this function in service layer 我在服务层有这个功能

public void confirmUser(String id)
{
      logger.debug("Confirming existing person");
      Session session = sessionFactory.getCurrentSession();
      String query = "FROM Registration WHERE uuid=:myuuid";
      Query query2 = session.createQuery(query);
      query2.setString("myuuid",id);
      Registration person = (Registration) query2.uniqueResult();
      person.setConfirmed(true);
      session.save(person);

}

Now i want to ask that does this same function go as it is in DAO function or something will remain in service layer as well 现在我想问一下,这个函数是否与DAO函数一样,或者某些东西也会保留在服务层中

Generally your DAO would do the work for storing and retrieving the entities, while your service would do the business logic. 通常,您的DAO将执行存储和检索实体的工作,而您的服务将执行业务逻辑。

So confirmUser(id) would be on the service, and would do the call to setConfirmed(..) on the user. 因此confirmUser(id)将在服务上,并将对用户执行setConfirmed(..)调用。

The DAO would have getUserById(id) and saveOrUpdateUser(User) -- or something to that affect, depending upon your needs. DAO将具有getUserById(id)和saveOrUpdateUser(User) - 或者具有影响的东西,具体取决于您的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM