From MVC and the three-tier architecture, we talk about SSH integrated development

Source: Internet
Author: User

I believe that many people agree that Javaweb development is in accordance with the MVC development model, and follows the three-tier architecture for development, yes, everyone agrees. But I believe everyone will have such a doubt, if (MVC three layer mode = = three Layer architecture idea) OUT.PRINTLN ("Please continue to watch ...")

1.MVC (Model-view-controller) design mode:

Let's start by understanding the concept of MVC (Model-view-controller):

The full name of MVC is the model View Controller, which is the abbreviation for the models-view-controller, a software design paradigm that organizes the code with a method of business logic, data, and interface display separation. Aggregating business logic into a single component does not require rewriting business logic while improving and personalizing the interface and user interaction. MVC is uniquely developed to map the traditional input, processing, and output functions in a logical graphical user interface structure.

    1. Model: A data model that provides the data to be presented, and therefore contains data and behavior, primarily providing features such as model data queries and status updates for model data, including data and business. Main technologies used: Data Model: Entity Class (JavaBean), data access: jdbc,hibernate, etc.,

    2. View: Responsible for the display of the model, generally we see the user interface, such as jsp,html, etc.

    3. Controller: Receives the user request, delegates to the model to process (state change), after processing, returns the returned model data to the view, which is displayed by the view. Main techniques used: Action class in Servlet,struts, etc.

MVC is a framework pattern that makes it mandatory to separate the input, processing, and output of an application. Using an MVC application is divided into three core parts: model, view, controller. Each of them handles their own tasks. The most typical MVC is the JSP + servlet + JavaBean pattern.

2. The three-tier architecture (Ui-bll-dal) concept introduces:

The three-tier architecture (3-tier architecture) typically has a three-tier architecture that divides the entire business application into: The presentation layer (User Interface layer), the business logic layer, the data access layer Access layer). The purpose of distinguishing hierarchy is to think of "high cohesion and low coupling". In the design of software architecture, layered structure is the most common and most important structure. Microsoft's recommended layered structure is generally divided into three tiers, from bottom to top: The data access layer, the business logic layer (or also called the domain layer), the presentation layer.

    1. Presentation Layer (UI): Popular speaking is to show the user interface, for displaying data and receiving user input data, to provide users with an interactive interface.

    2. Business Logic Layer (BLL): For the operation of the specific problem, it can also be said that the operation of the data layer, the data business logic processing. For the data access layer, it is the caller and, for the presentation layer, it is the callee. The business logic layer is also referred to as the domain layer.

    3. Data access Layer (DAL): This layer of transactions directly manipulate the database, the data to increase, delete, change, check. If you want to add an ORM element, it will include the mapping between the object and the data table, and the persistence of the object entity. Also known as the persistence layer. The data access layer contains the entity layer (Model entity layer)

The typical three-tier architecture in Javaweb is: Jsp+struts/spring+hibernate's development model

Differences and conversions between 3.MVC and three-tier architectures:
    1. The conceptual difference between MVC and the three-tier architecture:

MVC is a design pattern that we can use to create a distinction between a domain object and a UI presentation layer object. It is based on the specific needs of the project to determine whether it applies to the project.

The three-tier architecture is a layered software architecture design that can be applied to any project.

The three-tier architecture and the MVC design pattern are different, and the three layer is a general architectural idea, without limiting the specific design, and MVC is more specific about how it is designed. We start with a project, first of all, we need architectural design, generally we are using a layered architecture design, that is, our three-tier architecture. Then, after defining the architecture, we then consider whether we need to apply some design patterns, such as whether to apply our MVC pattern, abstract factory patterns, etc., according to the specific needs of the project.

The three layer focuses on a decoupling of the whole, while MVC focuses on decoupling of the web system, which focuses on a decoupling of JSP and servlet.

    1. The difference between MVC and the three-tier architecture is divided:

The three-tier architecture divides the entire project into a presentation layer (UI), a Business Logic layer (BLL), and a data access layer (DAL).

MVC: That is, model (models), view (view), Controller (control).

Can explain their differences and contact: Through the diagram can be seen is not one by one corresponding relationship: V is ui,c is bll,m is the Dal point of view is wrong.

    1. Conversion between the two:

Based on the three-tier architecture chosen in our project to decide whether or not to use MVC based on specific needs, we often say that MVC is always accompanied by a three-tier architecture, which makes it easy to confuse the two. In fact, we can see that MVC divides the UI in the 30% architecture into the control layer and the attempt layer. The data access layer and the business logic layer in the three-tier architecture are integrated into the model layer.

4. The MVC schema development for the three-tier architecture explains the SSH framework: 4.1 SSH Introduction:

The integration of multiple SSH frameworks (struts2+spring+hibernate) is now a popular open-source integration framework for enterprise and Web applications.

    1. STRUTS2:

Struts2 is a popular and mature Web application framework based on the MVC design pattern. Struts2 not just Struts1 the next version, it's a fully rewritten struts architecture. Struts provides the corresponding components for both Model,view and controller. However, in the process of SSH development, struts is used primarily as the presentation layer in the three-tier architecture, which is the view and control layer in MVC.

STRUTS2 provides form submission parameters encapsulated into the Pojo class, the type conversion of the commit parameter, input validation, file upload and download, program internationalization, Struts2 tag, and support for Ajax.

    1. Hibernate:

Hibernate is an open-source object-relational mapping framework that provides JDBC with a very lightweight object encapsulation that allows Java programmers to manipulate databases at will using object programming thinking. Hibernate can be applied to any JDBC application, either in a Java client program or in a servlet/jsp Web application, with the simple point that it is a more powerful JDBC.

Hibernate implements an object-to-database-side encapsulation. is often said Orm (object Relation Mapping), its appearance makes programming more object-oriented, in traditional programming, we want to store objects in a relational database, we need to write a lot of code to implement, and need to consider the problem of cross-database platform. With hibernate, you can easily convert from an object to a relational database. This is object persistence.

    1. Spring:

It consists of two important functions: IOC and AOP, which is often called dependency injection and aspect-oriented programming. Of course there are spring's transactional features, but this functionality is implemented in conjunction with the previous two features.

IOC: Dependency Injection (inversion of control) is a design pattern. One implication is the transfer of control: from the traditional control of dependencies in the program to the control by the container; the second layer is dependency injection: separating interdependent objects and describing their dependencies in the spring configuration file. Their dependencies are only established when they are used. Simply put, you don't need a new object.

AOP is an aspect-oriented programming idea that has made a historic progress in programming thinking. It cuts the execution of the program into different faces, and can insert the logic we want to execute between the faces.

4.2 SSH Hierarchical Division:

Javaweb Development Many times we are divided by this level:

1, in the presentation layer, first through the JSP page interactive interface, responsible for transmitting requests (request) and receive response (Response), and then struts according to the configuration file (Struts-config.xml) The request received by Actionservlet is delegated to the corresponding action handle, and then the action is processed on the request and forwarded to the JSP page.

2. In the business logic layer, the spring IOC container that manages the serviced component is responsible for providing specific action objects to STRUTS2, providing the business model component and the component's collaboration Object data Processing (DAO) component to complete the business logic, and provide transactional processing, Buffer pools and other container components to improve system performance and ensure data integrity.

3. In the data access layer, it relies on Hibernate's object mapping and database interaction, processing the data requested by the DAO component, and returning the processing result to the business logic layer.

When following the MVC pattern: The JSP corresponds to the presentation layer, the struts2 corresponds to the control layer, and spring and hibernate correspond to the model layer.

Stratification is not absolute, everyone's opinion is not the same, for reference only;

From the MVC point of the SSH integration Development introduced here, the next part is mainly the integration of SSH framework, will explain how to use SSH to develop a simple Web application.

From a little shark wpeace (rlovep.com)

From MVC and the three-tier architecture, we talk about SSH integrated development

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.