SSH and SSM comparison summary

Comparison and summary of SSH and SSM

This article is reproduced, the original address: http://www.toutiao.com/i6342638815143789058/

Two of the current popular enterprise development MVC open source frameworks are the necessary knowledge and ability of our Java programmers. MVC, the abbreviation of model-view-controller, a software design paradigm, organizes code with a method of separating business logic, data, and interface display, and aggregates business logic into one component Inside, there is no need to rewrite business logic while improving and customizing the interface and user interaction. The reason why the framework is popular is that it is easy to reuse and simplify development. The essence is in the idea. If you master the core idea, we will have no problem with other similar frameworks. It is recommended that you read the source code of the framework if you have the energy, especially spring.
SSH and SSM Definition
SSH usually refers to Struts2 as the controller, spring manages the components of each layer, and hibernate is responsible for the persistence layer.
SSM refers to SpringMVC as the controller, Spring manages the components of each layer, and MyBatis is responsible for the persistence layer.
Common points: 1. Spring dependency injection DI to manage the components of each layer. 2. Use aspect-oriented programming AOP to manage things, logs, permissions, etc.
Differences: 1.Struts2 and SpringMVC controllers control the interaction mechanism between views and models.
Struts2 is at the Action class level, and SpringMVC is at the method level, making it easier to implement RESTful style.
Implementation principle of SSH and SSM
1. Implementation principle of


Struts2 Struts2 framework execution steps (Struts2 uses Filter embedded):
1. The client initiates a request to a servlet container (such as Tomcat)
2. The request goes through a series of filters (one of these filters is an optional filter called ActionContextCleanUp, which is used for Struts2 and other The integration of the framework is very helpful
3. Then FilterDispatcher is called, and FilterDispatcher asks ActionMapper to decide whether the request needs to call an Action
4. If ActionMapper decides that an Action needs to be called, FilterDispatcher hands the processing of the request to ActionProxy
5. ActionProxy passes Configuration The Manager asks the configuration file of the framework to find the Action class that needs to be called
6. ActionProxy creates an instance of ActionInvocation.
7. The ActionInvocation instance is called using a naming pattern.
8. Once the Action is executed, ActionInvocation is responsible for finding the corresponding return result according to the configuration in struts.xml. The return result is usually (but not always, it may be another Action chain) a JSP or FreeMarker that needs to be represented 9.
Return the processing result to the client 2. SpringMVC
implementation principle


SpringMVC framework execution steps (SpringMVC uses Servlet embedding):
1. The client sends an http request to the web server, and the web server parses the http request. If it matches the request mapping path of the DispatcherServlet (specified in web.xml), the web container forwards the request to the DispatcherServlet.
2. The DispatcherServlet receives this After the request, the request handler (Handler) will be found according to the requested information (including URL, Http method, request header and request parameter Cookie, etc.) and the configuration of HandlerMapping.
3-4. The DispatcherServlet finds the corresponding Handler according to HandlerMapping, and gives the processing right to the Handler (the Handler encapsulates the specific processing), and then the specific HandlerAdapter makes a specific call to the Handler.
5. Handler will return a ModelAndView() object to DispatcherServlet after data processing is completed.
6. The ModelAndView() returned by Handler is just a logical view and not a formal view. DispatcherSevlet converts the logical view into a real view View through ViewResolver.
7. The Dispatcher parses the parameters in ModelAndView() through the model, and finally displays the complete view and returns it to the client.
Comparison of Hibernate and MyBatis ORM
frameworks The similarities between the two
Both Hibernate and MyBatis can generate SessionFactory from XML configuration file through SessionFactoryBuider, then SessionFactory generates Session, and finally Session starts to execute transactions and SQL statements. Among them, the life cycle of SessionFactoryBuider, SessionFactory, and Session is similar.
Both Hibernate and MyBatis support JDBC and JTA transactions.
Their respective advantages
MyBatis can perform more detailed SQL optimization and can reduce query fields.
MyBatis is easy to master, while Hibernate has a higher threshold.
Hibernate's DAO layer development is simpler than MyBatis, which needs to maintain SQL and result mapping.
Hibernate's maintenance and caching of objects is better than MyBatis, and it is more convenient to maintain objects that are added, deleted, and checked.
Hibernate database portability is very good, MyBatis database portability is not good, different databases need to write different SQL.
Hibernate has a better second-level cache mechanism and can use third-party caches. The caching mechanism provided by MyBatis itself is not good. The update operation cannot specify to refresh the specified record, and the entire table will be cleared, but a third-party cache can also be used.
Hibernate has good encapsulation, shields database differences, automatically generates SQL statements, has weak ability to cope with database changes, and is difficult to optimize SQL statements.
MyBatis only implements the mapping of SQL statements and objects. It needs to write SQL statements for specific databases, and has a strong ability to cope with database changes, and it is more convenient to optimize SQL statements.
Summarize
SSM and SSH are different mainly in MVC implementation and ORM persistence (Hiibernate and Mybatis). SSM is becoming more and more lightweight in configuration, making the most of annotation development, ORM implementation is more flexible, and SQL optimization is easier; while SSH pays more attention to configuration development, Hiibernate's complete encapsulation of JDBC is more object-oriented, and it is more object-oriented for adding, deleting, modifying and checking. The data maintenance is more automated, but the SQL optimization is weaker and the entry barrier is slightly higher.
Attached to the Spring family:


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326211867&siteId=291194637