Interface skeleton design of Web project architecture

Source: Internet
Author: User

Today began to update the summary of the last semester project, do not update immediately forget, but also share with Csdner, and we exchange about the system design method, welcome everyone to shoot bricks, throw bricks, pour cold water ...

1.spring+hibernate+struts2 Frame composition

1. Architecture Analysis Diagram

Straight, it's easy to analyze the truth.

The above architecture uses the MVC three layer architecture, wherein the M:model model Layer V:view View Layer C:control control layer, wherein the model layer has a variety of javabean to assume, the View view layer has a JSP (Struts2 tag) to act, The control layer has a Struts2 action to act as. The above is the point of view of the architecture, if the idea of engineering to achieve is Action-->Service-->DAO .

2. Technical analysis of each implementation

a.struts2: First explain Struts2 and Struts1 not much relationship, Struts2 is webwork and Struts1 development, but from the source point of view 60% of the core are inherited from the webwork. The action of Struts2 assigns an instance object to each request, because there is no thread-safe issue, but if the integration with spring must be aware of thread-safety issues, since spring's IOC container takes a singleton when managing Pojo, Therefore, the action must be set to the prototype ( scope:singleton|prototype|request|session|global session ) type.
Advantages of STRUTS2
* Based on filter design (low coupling)
* Native Servlet API
* Mass use of interceptors (responsibility chain mode)

B.hibernate: Responsible for the DAO layer, using connection pooling to provide database connectivity, although these are managed by spring, Hibernate's position in the Web is important. The persistence layer's framework actually not only hibernate also has mybatis, TopLink and so on, but only hibernate and MyBatis use more, if Hibernate compares to the automatic washing machine, then mybatis is the manual washing machine. Although it is convenient to use Hibernate to query without using a single SQL, it is not recommended in real-world projects, or it is more efficient to manipulate native SQL, while handwritten SQL can optimize query efficiency.

c.spring : How to describe Spring? In fact, the location of spring in web development is too important, if in a metaphor, it can be understood, "Spring is the equivalent of a rice cooker, and Hibernate, Struts2, MyBatis, Spring MVC framework equivalent to the various foods inside, All depend on the rice cooker, everyone can eat delicious. "Spring's birth is the advent of Java, hahaha ... In fact, spring in order to manage these frameworks using a very famous IOC (inversion of control) inversion of the idea of changing what used to be used in Java programs in the new one, now using the IOC is to make this thinking change, Objects are managed in the spring container, I can give you when the program needs it, you can recycle it, and all of the objects have a spring container throughout their life cycle. We only need to be responsible for the implementation of the business, which greatly facilitates the development.

At the same time, spring also uses a very important thought AOP (Aspect oriented programming) oriented aspect thinking, what is this? See:

The diagram shows the execution flow of a program, where the method in the red box represents the business method to be executed by the program itself, and AOP can cut into the method to be executed before and after the method is executed, so that the low-coupling idea of the program can be played into the mechanism. To give a very simple case: the red box is equivalent to the method of taking money, before the ATM machine to start the log method, security check, after the completion of the method after the completion of the operation to pull the card, and so on, wherein the starting log method, security check is equivalent to using AOP approach. AOP aspect-oriented programming implementation principle is dynamic agent, and dynamic agent is developed from the static agent, figuring out the static agent is very container to understand how AOP is going on, the current implementation of the mainstream agent has JDK agent and cglib agent, The JDK agent is based on the interface, so the advantage of extensibility is better, and Cglib is the final type, performance is not very good. In the following lecture, we will explain the principle of the implementation of AOP by the proxy mode.

2. Design of flexible interfaces in the infrastructure

1. Entity Relationship Design

One of the most important principles in design mode is the opening and closing principle : Open to extensions for modification closure. A good design is very rare and requires constant improvement and evolution. The following is an analysis based on a permission system case, the entity diagram is as follows:

Users and roles are one-to-many relationships, roles and permissions are many-to-many relationships, and permissions and resource links are a one-to-many relationship. In some systems, there are only users, roles, and resources in the design of permissions. This design has a more privileged entity because of the more detailed role permissions in large systems, so it helps to manage and manipulate permissions.

2. System interface Design

The interface design of the system is presented, in which the generic method in DAO is abstracted into commondao< T > and the generic design can be adapted to many entities, and then implemented in abstract method Commondaoimpl (abstract class). So that other daoimpl can directly inherit Commondaoimpl so it is very clear, and later extended Daoimpl directly inherit the generic implementation of the class can be. For the design of the Service Interface library, unify abstraction into commonservice< T >, then let Commonserviceimpl (abstract class) implement, Each serviceimpl can implement its own interface while inheriting Commonserviceimpl so that it can be implemented, the free extension, the same reason the entity instantiation in the action is placed in the parent class commonaction to implement, Subclass action to inherit directly. This design method is similar to the façade model, but it is much improved.

3. Project Process Analysis

The following is a brief explanation of the process of building a specific project framework:
1. Create Web project Settings project code to UTF-8
2. Create a project package structure

3. Write the configuration file consolidation framework in the following order
Struts2–>hibernate–>spring
Struts.xml–>web.xml–>hibernate.cfg.xml–>applicationcontext.xml–>web.xml
4. Writing test Entities
5. Write the test case with JUNIT4 and see that the Green Line is integrated successfully

All of these Web project infrastructures have been built successfully, and the next section summarizes the static agents and dynamic proxies in the proxy mode, explaining how the AOP principle is implemented.


Very happy to exchange study with everybody
Free reprint, creative license, please indicate the source of the article, from here
(Http://blog.csdn.net/unikylin)

Interface skeleton design of Web project architecture

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.