IX. Architecture and MVC Design Patterns of the Java EE

Source: Internet
Author: User

The Java EE specification proposes its own n-tiers structure.

In general applications, most of us are divided into the following ways:

Presentation layer: Manages the user's request, responds to the user's request, and displays the appropriate information to the user. The struts framework can process the user's request at the presentation layer, and the controller can invoke the underlying business logic, handle the exception, and validate the information entered by the user. The presentation layer can also select velocity, JSF, and so on.

Business Logic Layer: responsible for the implementation of business logic. The spring framework can handle the business logic of the application, the business validation, the management of the transaction, the management of the dependencies of the objects in the business layer, and the execution of the corresponding business processes to implement the business services.

Persistence layer: Responsible for access to the database. The Hibernate framework provides object-oriented persistence mechanisms and query services for Java in the persistence layer. Object-oriented methods can be used to store, update, delete records of a database, and query database information. Persistent layer can also choose Ibatis, etc.

Data layer: Used to store business data for the upper call, mainly refers to some database systems.

The 3 framework features of the classic SSH (Struts, Spring, Hibernate) are different, and depending on the functional hierarchy of the Web application, these 3 frameworks can be applied to various levels, ultimately enabling the functionality of each layer to complete the integration.

Struts is applied at the presentation layer, the spring application in the business logic layer, and hibernate in the persistence layer.

When it comes to the layered structure of Java EE, we have to talk about MVC design patterns.

The MVC design pattern separates model, view, and control, reducing the coupling between components, while the model component can be reused by other components in the system, which improves the reusability of the code.

Model: A standalone component, or development module. Responsible for the processing of business logic in the application. The model encapsulates the business logic into separate modules and is available to different developers. And these stand-alone modules can be assembled as needed.

Views View: Represents the interface that interacts with the user. The view is responsible for displaying the data collected from the model or the data entered by the user and the delivery of the request, passing the data and requests to the controller and the model.

Controller controllers: is responsible for distributing the requirements of the view to all the models on which the view depends, and after the model has changed, distributing the changes to all the views corresponding to the model, and the contents of the view will change. A view can depend on multiple models, and a model can correspond to multiple views.

In summary, the principle of the MVC design pattern is that when an event occurs, the view sends the client request to the Controller,controller to change the model or view. If the controller changes the model data, all the model-dependent views are notified by the controller, and the view will state the model, and the model will make the status query and notify the view to change. Similarly, if the controller changes the View,view will fetch the relevant data from the dependent model and refresh the view itself.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.