JSF Controller, Service and DAO

后端 未结 2 2250
情书的邮戳
情书的邮戳 2020-11-21 07:16

I\'m trying to get used to how JSF works with regards to accessing data (coming from a spring background)

I\'m creating a simple example that maintains a list of use

2条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-21 07:48

    It is a DAO, well actually a repository but don't worry about that difference too much, as it is accessing the database using the persistence context.

    You should create a Service class, that wraps that method and is where the transactions are invoked.

    Sometimes the service classes feel unnecessary, but when you have a service method that calls many DAO methods, their use is more warranted.

    I normally end up just creating the service, even if it does feel unnecessary, to ensure the patterns stay the same and the DAO is never injected directly.

    This adds an extra layer of abstraction making future refactoring more flexible.

提交回复
热议问题