Basic analysis of ssm framework

Review the ssm in the 10 days of training. The SSM framework is Spring+SpringMVC+MyBatis.

1. Spring is an open source framework. Spring is a lightweight Java development framework that emerged in 2003. Spring uses basic JavaBeans to implement it. Simply put, Spring has two big ideas, one is inversion of control (IoC) and aspect-oriented (AOP).

Spring is like a big factory in the project, responsible for assembly.

1.1 IOC (Inversion of Control)

​ The so-called inversion of control means to transfer the power of the generated object to spring to control it. The coupling between the object and the object is reduced. You don't need to know how to achieve it. Just use it and Spring will use it. One by one is good, which means that one by one is good. In fact, we still need to write the configuration manually. The configuration is really cumbersome when we first get started. (Rely on SpringBoot to solve this annoying configuration)

1.2 AOP (Aspect Programming)

In fact, in my opinion, the so-called aspect programming is a proxy method. Generate a proxy object, and then cut the method to the front and back of the object and exceptions, which can reduce the use of repeated code. For example, when operating a database, you have to open and commit transactions every time. These things can be done by proxy objects.

2.Spring MVC 

Separate the roles of controller, model object, dispatcher, and handler object, and implement it according to requirements after separation. SpringMVC is equivalent to doing all the original Servlet, but it is more convenient than Servlet. It is called Controller in SpringMVC.器), there are a total of the following components.

1. Front controller (DispatcherServlet) 2. Handler Mapping 3. Handler 4. Handler adapter (HandlAdapter) 5. View Resolver 6. View

​ org.springframework.web.servlet.DispatcherServlet is equivalent to a filter. All requests must pass through this controller first, and then decide where you want to go and which method you want to execute. This core controller comes in, he is in Assign method execution to you according to your request information, and then if your method return value is String, then he will look for the JSP or HTML page according to the view parser, and then return it to you. If it is an object, he Can return a Json string.

3.MyBatis 

Is a Java-based persistence layer framework. MyBatis eliminates almost all manual setting of JDBC code and parameters and retrieval of result sets. MyBatis uses simple XML or annotations for setting and primitive mapping, mapping interfaces and Java POJOs (Plain Old Java Objects) into records in the database. Mybatis framework, this is a framework for the persistence layer. It encapsulates the database a bit, but it is not as thorough as hibernate. It still needs to write SQL statements manually, so database query operations can be tuned.

​ Mybatis feels the more difficult part is one-to-many and many-to-one. One-to-many feels that I am not particularly proficient or pay attention. Then you can use MyBatis Plus to quickly generate it.

4. Final ssm integration

The ssm is to integrate the three frameworks based on the three-tier architecture model. The idea of ​​integration is to hand over the control of transactions to Spring for declarative transaction control, and the Session factory to the Spring container for management, and obtain execution operations from the container. Mapper instance.

Guess you like

Origin blog.csdn.net/qq_43458555/article/details/107979583