Summary of java back-end development interview

 1. The core of Spring is inversion of control (IoC) and aspect-oriented (AOP)

Inversion of control:
IOC and DI are two core concepts of Spring. Although the two are talking about the same thing, they are not exactly the same.
IOC (Inversion of Control): Inversion of Control. 
DI (Dependency Injection): Dependency Injection.
The conclusion drawn:
Inversion of control is the purpose, and dependency injection is the means to achieve inversion of control. 
Inversion of control is an object-oriented idea, but it is only a broad concept. As long as a class transfers control of its internal state to other mechanisms, it is called "inversion of control". Inversion of control is to reduce the degree of coupling between classes. 
Spring uses dependency injection as a specific method to achieve the purpose of inversion of control. 
Dependency injection
A simple example:

class A {
    private B b;
}

We can explain this code like this:

There is a dependency relationship between A and B;
A depends on B;
A is a dependent class;
B is a dependent class.
Generally, dependent classes need to create and maintain objects of dependent classes by themselves, such as:

       class A {
            private B b = new B();
        }

However, the method of dependency injection is 
to delegate the creation of the dependent object to a special organization to do it, and to declare the required member variables in the dependent class. Obviously, in this example, the approach is that class A no longer creates class B, that is, no new B() is used, and it is handed over to a special organization to create and maintain class B. Class A only needs to declare B; 
that is, Dependent classes originally need to take the initiative to obtain objects, but after using dependency injection, the objects are provided by third-party organizations, and you only need to declare what objects you need. In Spring, the third-party organization that creates and manages objects is called "IoC Service Provider". 
The purpose of this is to reduce the degree of coupling between the two classes.

Aspect-oriented:

AOP crosscut timing

In Spring's AOP, there are 4 most commonly used crosscutting timings, namely before the pointcut execution (@Before), after the pointcut execution (@After and @AfterReturing), when an exception is thrown (@AfterThrowing), and surrounding notification (@Round) and their combination.

2. Servlet life cycle

1. Load and instantiate

2. Initialization

3. Request processing

4. Termination of service

The working process of the Servlet when the Web server interacts with the client is:

1. Make a request to the web server on the client side

2. After receiving the request, the web server sends it to the Servlet

3. The Servlet container generates an instance object for this purpose and calls the corresponding method in the Servlet API to process the client HTTP request, and then returns the processed response result to the WEB server.

4. The web server sends the response structure received from the Servlet instance object back to the client.

3. The power of springMVC

1. Spring MVC implements the core concept of ready-to-use MVC. It provides a large number of functions related to this mode for controllers and handlers. And when the Inversion of Control (IoC) is added to MVC, it makes the application highly decoupled and provides the flexibility to dynamically change components through simple configuration changes. Spring MVC provides you with the power to fully control all aspects of your application.

2. Spring's Web MVC module is designed around DispatcherServlet. DispatcherServlet dispatches requests to handlers, performs view resolution, and handles locale and theme resolution, and also provides support for uploading files.

3. DispatcherServlet uses the handler mapping to determine which handler should handle the incoming request. The handler mapping is just a mapping used to identify which handler is used to process a specific URL pattern. The handler is an implementation of the controller interface with only one method ModelAndView handleRequest(request,response). Spring also has some advanced handler implementations available; one of the important advanced handler implementations is SimpleFormController, which provides functions such as binding command objects to forms and performing validation on them.

4. You have used DispatcherServlet and simple handlers in previous tutorials in this series. In the next section, you will use SimpleFormController and explain the various ready-to-use functions provided by Spring MVC.

Guess you like

Origin blog.csdn.net/Draven__/article/details/90733079