Why matters generally added service layer

1, applied to Comparative transaction service layer and layer dao

    Four characteristic combination transaction (ACID), it can well explain why the increase in the service layer. First, if the transaction annotation @Transactional added dao layer, as long as do additions and deletions to the database, you need to submit a transaction ; so do the characteristics of the transaction will play out, especially transactional consistency, when there is concurrency issues, from database data are likely to be found in the presence of bias. 

    In general, the method calls the service layer of a plurality of layers dao, only on the method of service layer, plus a transaction can @Transactional annotation; thus, a transaction request using a plurality of databases, the transaction will be a characteristic full play.


2, plus the difference between the layers affairs

Spring transaction management transaction business logic, business logic to ensure the atomicity of data.

According to the project nature of the transaction have to be broken down: the transaction can be set to three levels (dao layer, service layer and web layer). 

First: controller layer Affairs

    This is generally for those high security requirements of the system it is. Such as e-commerce sites. Small size, the general system need not be so fine. 

Second: service layer Affairs

   This is a common transaction demarcation, set the transaction on the business logic, as long as the business logic errors or anomalies on a transaction rollback. Small size, generally recommend this approach .

Third: dao layer data traffic

   Is often said that the database transaction. This transaction requires low in terms of safety. It is to give a simple CRUD operations like increased transaction operations. Large particle size.

   Service layer is disposed to the transaction, since the method of operating a Service layer DAO can be associated to a plurality of operations. Service layer in the execution of these operations Dao, multiple DAO operations have failed are rolled back, then all successfully submitted.

    Services are divided into business transactions and system transactions, business transaction is consistent operation of the business logic, the system refers to the true nature of the transaction database transactions,

    Spring configuration transaction is to manage what is, of course, transaction management business logic, business logic to ensure the atomicity of data;

    What is Dao layer, data access layer, should not contain business logic, which is different and Service layer;

    Service layer is to manage the business logic, the transaction is to ensure that the Service layer.


reference:

https://blog.csdn.net/panyangxu/article/details/77431873

https://www.cnblogs.com/hutton/p/5493095.html

 

 

Guess you like

Origin blog.csdn.net/jiahao1186/article/details/91567701