Relayering Based on SSH development architecture

Source: Internet
Author: User

In modern enterprise development, multi-layer architecture design is increasingly introduced. Struts + Spring + Hibernate (SSH for short) is one of them. The SSH architecture is currently a very popular architecture, with many financial and telecom projects, all major portal websites use this architecture as the business support architecture, and the development process is very mature. However, there are still some problems in the development of this structure. To analyze these problems, we must first start with the composition of the SSH architecture.

SSH is a combination of Struts + Spring + Hibernate. Struts implements MVC. Spring is responsible for the combination of architectures and Hibernate for data persistence. Generally, its hierarchical development structure (taking a new business as an example) is as follows:

This structure meets the general business needs. However, there are many problems in the development of the increasingly complicated WEB2.0, which are summarized as follows:

A) DAO and the Service layer are prone to unclear responsibilities. According to the MVC logic, the Business Code should be written in Struts Action, but the provision of its transactions is configured in the Service layer. For a set of logically complete data operation business logic, it must involve two layers of Serveice and Action) for writing. In case of judgment, in order to ensure the complete transaction operation, you need to move the Business Code to the Service layer, the business data of the Service transaction called before the operation is not rolled back when multiple services are called in the Struts Action and multiple transactions are generated when an Exception occurs.

B) when the data to be returned is used by AJAX and JSON or XML is used in a large amount. It may be very laborious to develop a piece of the same business code. In order to use AJAX and XML, you may need to re-compile it, or use a flag in the same ACTION to judge, this has caused bad damage to the layered structure. If the design is poor, a large number of additional configurations are required to use JSON and XML, which seriously reduces the development efficiency.

Therefore, in order to overcome these shortcomings, I have implemented a new layer for the SSH architecture and shared the Business Code. Simplified development and enhanced integration with AJAX and MXL technologies. Provides a more efficient development mode.

Its development structure is as follows:

Someone may ask, where is the Struts Action class written? The answer is exactly the advantage of this architecture. Because the Business Code implements the IbusinessService interface in a unified manner, you only need to call the Service layer methods by several fixed Struts Action classes. Including JSON output, XML output, and WebService output, all call the Service layer method to complete the function. In this way, the Business Code is separated and greatly decoupled from the front-end framework.

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.