Understanding of springIOC
- IoC (Inversion of Control): Inversion of Control. It is a design pattern, the spring framework is responsible for controlling the life cycle of objects and the relationship between objects
- Four characteristics of Spring:
- lightweight
- Dependency injection: Dynamically provide an object with other objects it needs while the system is running
- Aspect-Oriented Programming
- is a container
- In applicationContext.xml by injecting
- SpringIOC can manage the life cycle of beans. The management process is:
- Create bean instance via constructor or factory method
- By assigning a value to the bean's object
- Call the bean's initialization method
Understanding of SpringMVC
- MVC(Model, View and Controller)
- SpringMVC is a Java-based lightweight web framework that implements the request-driven type of the Web MVC design pattern. It uses the idea of the MVC architecture pattern to decouple the responsibilities of the web layer. Request-driven refers to the use of request ( Request)-Response (Response) model, the purpose of the framework is to help us simplify development.
- SpringMVC process description:
- The user sends a request to the server, which is captured by the front controller DispatcherServlet
- DispatcherServlet parses the request URL and obtains the request resource identifier (URI). Then according to the URI, call the handler mapper (HandlerMapping)
- DispatcherServlet generates handler object and handler interceptor according to the obtained Handler, and returns it to DispatcherServlet
- DispatcherServlet calls the handler (Handler) through the handler adapter (HandlerAdapter)
- Processor (Controller) execution
- When done, returns a ModelAndView object
- HandlerAdapter returns ModelAndView to DispatcherServlet
- DispatcherServlet passes ModelAndView to ViewReslover view resolver
- ViewReslover returns the corresponding View after parsing
- DispatcherServlet renders the View (that is, fills the model data into the view)
- DispatcherServlet responds the rendered view to the user
The difference between injection by constructor and injection by setter method
Injection via setter method:
<bean id=BEAN_ID class=CLASS_PATH> <property name=PROPERTY_NAME value=PROPERTY_VALUE> </bean>
Injection via constructor:
<bean id=BEAN_ID class=CLASS_PATH> <!-- 按照索引匹配注入--> <constructor-arg index=ARG_INDEX value=ARG_VALUE> <!-- 按类型匹配注入--> <constructor-arg type=ARG_TYPE value=ARG_VALUE> </bean>