Day60
可以在方法处传入Map、或Model或者ModelMap
给这些参数里面保存的所有数据都会放在请求域中,可以在页面获取
Map、Model、ModelMap ,最终在都是BindingAwareModelMap在工作。
相当于给BindingAwareModelMap中保存的东西都会放在请求域中。
Map(interface(jdk))
Model(interface(Spring))
ModelMap(class) 继承于Map下。
数据都放在request域中,既安全又快速。
尽量别用@SessionAttributes,用原生SessionAPI放数据。
@ModelAttribute
参数:取出 刚才的参数
这个方法会提前与目标方法先运行。
参数的Map: BindgAwareModelMap。
SpringMVC源码
1.前端控制器的架构:DispatcherServlet:
FrameWorkServlet
HttpServletBean
DO
doDispatch()方法的详细源码分析。
protected void doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception {
HttpServletRequest processedRequest = request;
HandlerExecutionChain mappedHandler = null;
boolean multipartRequestParsed = false;
WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
try {
ModelAndView mv = null;
Exception dispatchException = null;
try {
//1.检查当前是否文件上传请求。
processedRequest = checkMultipart(request);
multipartRequestParsed = (processedRequest != request);
// Determine handler for the current request.
//2.根据当前的请求地址找到哪个类能来处理。
mappedHandler = getHandler(processedRequest);
//3.如果没有找到哪个处理器(控制器)能处理这个请求,就404,或者抛异常。
if (mappedHandler == null) {
noHandlerFound(processedRequest, response);
return;
}
// Determine handler adapter for the current request.
//4.拿到能执行这个类的所有方法的适配器。(拿到反射工具)
//这里的ha = AnntotationMethodHandlerAdpter
HandlerAdapter ha = getHandlerAdapter(mappedHandler.getHandler());
// Process last-modified header, if supported by the handler.
String method = request.getMethod();
boolean isGet = "GET".equals(method);
if (isGet || "HEAD".equals(method)) {
long lastModified = ha.getLastModified(request, mappedHandler.getHandler());
if (new ServletWebRequest(request, response).checkNotModified(lastModified) && isGet) {
