No standards can be achieved, and no cooperation can be achieved without norms

Hierarchical parameter passing and naming processes

  • Dao layer is the data layer, which directly carries out database read and write operations and returns data object DO, which corresponds to database tables one by one.
  • The Service layer is the business layer that implements business logic. Can call the DAO layer or service layer, return the data object DO or business object BO, BO is usually transformed by DO, integration, can contain multiple DO attributes, can also contain only a DO part of the attributes. Usually for simplicity, a service can return DO directly if no conversion is required. External call (HTTP, RPC) methods are also in this layer, and for external calls, services typically convert dtos returned by the external call to BOS.
  • The Controller layer is the control layer that handles external requests. Call the Service layer, convert the BO/DO returned by the Service layer into DTO/VO and return it to the caller as a unified return object. VO is returned if the data is used for front-end template rendering, DTO is generally returned otherwise. No matter DTO or VO, data in BO/DO are generally transformed and integrated, for example, 0 in gender attribute is converted to “male” and 1 to “female”.

Be clear about responsibilities

The controller layer of responsibility

1. Verify parameters

2. Invoke the service layer interface to implement the service logic

3. Transform business/data objects

4. Assemble the return object

5. Exception handling

The service layer of responsibility

1. Receive Controller layer data

2. Interact with the DAO layer to process business logic

3. Generate DTO data and return it to the Controller layer

The dao layer of responsibility

1. Database read and write

2. Return the base type or DO to the service layer

3. Avoid adding service logic

Refer to Ali code specification: Ali code specification