background
Some time ago to write before the DAO framework ( handwriting DAO framework (a) - from "1" ) sorted out, a reconstructed version. Finishing process seen in the code used to write, just to understand the implementation, but in order to achieve, write the code a bit rough. Now that you've compiled DAO framework, simply continue to sort out the MVC framework (https://github.com/shuimutong/zxmvc.git), also called learn new things.
I, on the Servlet
1 Introduction
When studying the web, they are generally the first to learn Servlet
You can receive the request via http Servlet, and response
This time there was no need struts, SpringMVC and other frameworks
2、tomcat、jetty
web application server
servlet container
servlet container needs to run
3, servlet life cycle
Load servlet 1) service starts
2) when the first request
2.1) Examples of servlet
2.2) the init method
3) calls the service method, the type of request is determined
3.1) get the type of method calls doGet
3.2) post type is called doPost method
4) when the service restart or shutdown, call the destroy method
Two, MVC framework
Model (model)
Portion for processing the application logic of the application data
View (View)
Processing data of the application display
Controller (Controller)
Application user interaction processing section
Three, SpringMVC
1 Overview
Controller receives the request, and then returns ModelAndView
2, the request processing flow
Other modules 1) SpringMVC submit all requests to DispatcherServlet, it commissioned the application system is responsible for processing requests for real
2) DispatcherServlet query HandleMapping, find Controller to process the request
3) DispatcherServlet submit requests to the target Controller
4) Controller business logic processing, return a ModelAndView
5) DispatcherServlet query ViewResolver view resolver, find the specified object view object ModelAndView
6) The page rendering to the browser
3, thinking
1) About view resolver
Previous page frequently used freeMarker, jsp, etc., you need to go through to view Html parser
Personally feel that the above two methods, not as a direct html, js through the brush to the intuitive page
Write your own MVC framework, you can achieve MC, V temporarily use html
2) The main function
Encapsulates servlet
IOC: instance management
AOP: Dynamic Proxy, cglib
Fourth, the realization of ideas
1, how to receive the request, the request distribution
Similar DispatcherServlet
Service initially scan all URI, and placed in a URIMAP
It is defined to receive all requests a Servlet
URIMAP URL matches the corresponding request according Controller
A request to the corresponding Controller
2, IOC how
Notes form
Definition requires comment
When the service starts, the scan annotated classes
The annotated according to instantiate a class dependent (by reflection)
3、AOP
Postpone realization
Fifth, the implementation overview
1. Implementation Notes
1) layers comment
Controller、Service、Repository、Component
2) Automatic injection annotations
Autowired
3) URI commentary
RequestMapping
2, a scanning type annotations
Scanning fill URI
3, to achieve DispatcherServlet
1) receiving a request
2) distribution request
FIG attached Brain: