Spring is like a large factory for assembly beans throughout the project. In the configuration file, you can specify specific parameters to invoke the constructor of the entity class to instantiate the object. The core idea of Spring is IoC (Inversion of Control), which means that instead of requiring programmers to explicitly new an object, you let the Spring framework do it for you.

SpringMVC intercepts user requests in a project. Its core Servlet, the DispatcherServlet, acts as an intermediary or foreground to match user requests to the Controller through HandlerMapping. A Controller is the action that is performed for a specific request. SpringMVC is equivalent to Struts in the SSH framework.

Mybatis mybatis is the encapsulation of JDBC, which makes the underlying operation of the database transparent. Mybatis operates around an instance of sqlSessionFactory. Mybatis is associated with the Mapper file of each entity class through the configuration file, and the Mapper file configures the SQL statement mapping required by each class to the database. Every time you interact with the database, get a sqlSession through sqlSessionFactory, and then execute SQL commands.

SSH and SSM definitions

SSH usually refers to Struts2 as controller, Spring manages the components of each layer, and Hibernate takes care of 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: 1.Spring dependency injection DI to manage components at all levels. 2. Use section-oriented programming AOP to manage transactions, logs, permissions, etc.

Differences: 1.Struts2 and SpringMVC controller (Controller) control view and model interaction mechanism,

Struts2 is at the Action class level, while SpringMVC is at the method level, making it easier to implement a RESTful style.

Hibernate and MyBatis two ORM framework comparison

Similarities between the two

Hibernate and MyBatis can use sessionFactoryBuilder to generate the SessionFactory from XML configuration file, and then the SessionFactory generates the Session, and finally the Session starts the execution of transactions and SQL statements. SessionFactoryBuider, SessionFactory, and Session all have the same life cycle.

Hibernate and MyBatis both support JDBC and JTA transactions.

Advantages of both

MyBatis can be more detailed SQL optimization, can reduce the query fields.

MyBatis is easy to master, while Hibernate has a higher threshold.

Hibernate’s DAO layer development is simpler than MyBatis, which maintains SQL and result mappings.

Hibernate maintains and cache objects better than MyBatis, and it is more convenient to maintain objects that are added, deleted, changed 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 caching mechanism and can use third-party caches. The cache mechanism provided by MyBatis itself is not good, the update operation can not specify the refresh of the specified record, will clear the entire table, but you can also use third-party cache.

Hibernate has good encapsulation, shields database differences, automatically generates SQL statements, and has weak ability to cope with database changes, making SQL statement optimization difficult.

MyBatis only realizes the mapping of SQL statements and objects. It needs to write SQL statements for specific databases. It has strong ability to cope with database changes and SQL statement optimization is convenient.

conclusion

SSM differs from SSH mainly in MVC implementation and ORM persistence (Hiibernate vs. Mybatis). SSM is more and more lightweight configuration, annotation development to the extreme, and ORM implementation is more flexible, SQL optimization is easier; SSH, on the other hand, pays more attention to configuration development. Hiibernate is more object-oriented in the complete encapsulation of JDBC and more automatic in the maintenance of data adding, deleting, changing, and checking. However, IT is weak in SQL optimization and has a higher threshold for entry.