Java Web Project MVC Open source framework ssh and SSM comparison __java

Source: Internet
Author: User
Tags java web

SSH and SSM definitions

SSH is usually referred to as the STRUTS2 Controller (Controller), spring manages the components of each layer, and the hibernate is responsible for the persistence layer.

The SSM refers to the SPRINGMVC Controller (Controller), Spring manages the components of each layer, and the mybatis is responsible for the persistence layer.

Common Ground: 1. Spring relies on injecting di to manage the components of each layer. 2. Use AOP to manage things, journals, permissions, etc.

different points: 1. The Struts2 and SPRINGMVC Controllers (Controller) control the interaction between the view and the model,

Struts2 is the action class level, SPRINGMVC is the method level, easier to implement restful style.

principles of SSH and SSM implementation

The realization principle of 1.struts2

Struts2 Framework Execution steps (Struts2 using filter embedding):

1. Client Initializes a request to a servlet container (for example, Tomcat)

2. This request passes through a series of filters (filter), which has an optional filter called Actioncontextcleanup, which is useful for integration of Struts2 and other frameworks

3, then Filterdispatcher is called, Filterdispatcher asks Actionmapper to determine whether the request needs to invoke an action

4. If Actionmapper decides to call a action,filterdispatcher to give actionproxy the processing of the request

5, Actionproxy through the configuration Manager to ask the framework's configuration file, to find the action class needs to call

6, Actionproxy to create a actioninvocation instance.

7, the Actioninvocation instance uses the naming pattern to invoke, before and after invokes the action the procedure, involves the related interceptor (Intercepter) the call.

8. Once the action is completed, Actioninvocation is responsible for finding the corresponding return result according to the configuration in Struts.xml. The return result is usually (but not always, or perhaps another action chain) a JSP or freemarker template that needs to be represented.

9, return the processing result to the client

The realization principle of 2.SpringMVC

SPRINGMVC Framework Execution steps (SPRINGMVC using servlet embedding):

1, the client issued an HTTP request to the Web server, the Web server to the HTTP request parsing, If the matching Dispatcherservlet request mapping path (specified in Web.xml), the Web container transfers the request to Dispatcherservlet.

2. After receiving this request, Dipatcherservlet will find the processor (Handler) processing the request based on the requested information (including URL, HTTP method, request header, request parameter cookie, and so on) and handlermapping configuration.

3-4, Dispatcherservlet according to handlermapping find the corresponding handler, the processing power to handler (handler will be the specific processing of encapsulation), Then by the concrete handleradapter to handler to make the specific call.

5. Handler will return a Modelandview () object to Dispatcherservlet after the completion of the data processing.

6, Handler returned Modelandview () is only a logical view is not a formal view, dispatchersevlet through the viewresolver of the logical view into the real view.

7, dispatcher through the model to resolve the Modelandview () the parameters in the final display of the complete view and return to the client.

comparison of two ORM frameworks between Hibernate and MyBatis

the same point of the two

both Hibernate and MyBatis can be generated by the Sessionfactorybuider XML configuration file Sessionfactory, and then the session is generated by Sessionfactory. Finally, the session opens the execution transaction and the SQL statement. The life cycle of the sessionfactorybuider,sessionfactory,session is similar.

both Hibernate and MyBatis support JDBC and JTA transaction processing.

each of the two advantages

MyBatis can perform more granular SQL optimizations to reduce query fields.

MyBatis easy to master, and hibernate threshold is higher.

Hibernate's DAO layer development is simpler than mybatis, and mybatis needs to maintain SQL and result mappings.

hibernate is better than mybatis to maintain and cache objects, and it is convenient for the maintenance of the objects to be modified and deleted.

Hibernate database portability is very good, MyBatis database portability is not good, different databases need to write different SQL.

hibernate has a better level two caching mechanism and can use third party caching. MyBatis itself provides a poor caching mechanism, the update operation cannot specify a refresh of the specified record, clears the entire table, but can also use a third-party cache.

Hibernate encapsulation is good, shielding the database differences, automatic generation of SQL statements, the ability to respond to database changes is weak, SQL statement optimization difficulties.

MyBatis only realizes the mapping of SQL statements and objects, needs to write SQL statements for the specific database, and it is more convenient to solve the database change ability and SQL statement optimization.

Summary

SSM and SSH differ primarily in the way MVC is implemented, and in ORM Persistence (Hiibernate and MyBatis). The SSM is increasingly lightweight configuration, the annotation development to the extreme, and the ORM implementation is more flexible, the SQL optimization is simpler, while SSH is more focused on configuration development, which hiibernate to the full package of JDBC more object-oriented, to add or delete changes to the data maintenance more automated, but SQL optimization is weaker, And the entry threshold is slightly higher.

Related Article

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.