Java EE application built based on SSH2 framework (1)

Source: Internet
Author: User

I. Preface

Although Struts2 + Spring3 + Hibernate3 has been on the market for a long time, it is still the preferred technology for many Java EE applications. This article will describe the architecture, ideas, technologies, and skills of the SSH2 application, and link up the Ren du of JavaEE, quickly Master the development process and key technologies of Java EE applications.

 


This article is not intended for readers without a Java Foundation. You need to master certain programming ideas, Java technology, Struts2, Spring3, Hibernate3 and other framework technologies, and understand Oracle and other DBMS.

 

 


Ii. JavaEE Architecture

The JavaEE architecture adopts the traditional MVC design Model and consists of three layers: Model, View, and Controller. Model is the Model layer, which defines the data Model and business logic. To separate data access from business logic, improve business precision, and reduce code coupling, the model layer is subdivided into DAO layer and business layer, DAO is called a Data Access Object (Data Access Object). It closes the database Access code, and the Hibernate API is also encapsulated here. It is no longer exposed to other layers or to other layers; the business layer is the core and most valuable layer of the entire system. This layer encapsulates application business logic, processes data, and focuses on customer needs, the DAO class provided by the DAO layer can help the business layer to complete data processing if raw data is accessed or new data is generated during business processing, or persistent data is required, the business layer itself focuses on the understanding of customer needs and the adaptation of business rules. Naturally, it also includes most calculations. In general, DAO does not process business logic and only provides assistance for the business layer, obtain raw data or persistent data. View is the View layer, which provides end users with a friendly interactive interface. Users can View the request results, or use forms and other interactive means to input data. The Controller layer is the Controller. The Controller is a bridge between the Model and the View. It connects the two to receive user data through the View, and the Controller transfers the data to the Model to process the data; or, after the Model reads the data, the Controller transmits the data to the View, and the View displays the data to the user. As a result, the Controller becomes the happy messenger between the Model and View.

 

 

For more information about MVC, please refer to Baidu encyclopedia Link (http://baike.baidu.com/view/31.htm), shows the structure of MVC:


From the call relationship perspective, the left is the upper layer, the right is the lower layer, the lower is the upper layer, and the upper layer can call the lower layer, but the lower layer cannot call the upper layer, calls between layers are unidirectional.

 


From the perspective of data transmission, data can be transmitted from the view layer to DAO and then saved to the database. data can also be read from the database for processing or display. Therefore, data transmission is bidirectional.

 


Technically, the view layer is implemented using HTML/JSP components, the controller is implemented using Servlet or Action components, and the model layer is implemented using JavaBean components or EJB technology.

 


Hibernate is encapsulated in the DAO layer and is responsible for data access operations. Struts acts as a controller, checks User Data Validity and converts data types, and provides labels for the view layer to simplify page display and provide international support; spring is the manager of applications. DAO, Service, Action, and other objects are created and maintained by Spring, and declarative transaction management is provided to simplify transaction programming.

 

 


3. How to understand the business?

The business in software engineering is different from the business in daily life. The common business refers to sales and refers to the transaction to be processed. Here, the business involves more than one organization, and a series of processes are implemented based on a common goal and through information exchange. Each process has a clear purpose and continues for a period of time. The scope is more limited. A business refers to a series of activities to complete a transaction. It requires the participation of objects and triggers a series of behaviors according to certain rules.

 


The business includes three elements: objects, behaviors, and business rules.

 


An object is a subject and a trigger of behavior. The object here may be a user, order, product, or DAO object, or an external system, such as a payment system. An object may be involved in the completion of a business, or multiple objects may be involved, depending on the business itself. Action is the action of an object. Multiple actions are executed in a certain order, forming the complete execution capability of the business. Business Rules are a constraint on the business. The results of each behavior must be responsible for the rules. The rules monitor the objects, behaviors, and results of business execution to ensure the correctness and accuracy of the business.

 


Take the withdrawal business as an example to analyze the objects, behaviors, and rules involved in this business.

 


Withdrawal Business Description: Enter the user account (the Bank swipe card is complete), remind the user to enter the password, the bank system checks the password is correct, if correct, the user enters the withdrawal amount, the system changes the account amount, records the withdrawal information, prints the bill, and completes the withdrawal.

 


This is a common business. From this business, we extract the following elements:

Objects: account, transaction, and printer;

Behavior: Check the card number and password, change the account balance, record the withdrawal transaction information, and print the ticket;

Rule: a maximum of 2000 yuan can be obtained at a time, and a maximum of 5 times a day can be obtained. An appointment is required if the withdrawal amount is greater than 50000;

 

Based on the above analysis, we can easily convert it into source code. Most of the time, the business we encounter is much more complicated than this, and the project scale is also large. This requires us to have a visual view, control the whole site, strategize, analyze carefully, and assist in modeling, achieve the best results.

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.