当前位置: 首页 > news >正文

做响应式网站设计做图怎么搞seo zac

做响应式网站设计做图怎么搞,seo zac,如何生成网站,连云港企业网站建设前面我们学习了 Spring 最核心的 IoC 与 AOP 模块(读书笔记-《Spring技术内幕》(一)IoC容器的实现、读书笔记-《Spring技术内幕》(二)AOP的实现),接下来继续学习 MVC,其同样也是经典…

前面我们学习了 Spring 最核心的 IoC 与 AOP 模块(读书笔记-《Spring技术内幕》(一)IoC容器的实现、读书笔记-《Spring技术内幕》(二)AOP的实现),接下来继续学习 MVC,其同样也是经典。

我们依旧按照从浅到深的方式来学习,先从程序员的视角看看其简化了哪些工作,帮我们做了什么,再到具体的设计与实现。


01

MVC 概述

在之前 IoC 的笔记中,有这样一张图:

这里依然可以复用,从程序员的视角来看,Spring MVC 带来的最直观的好处是,我们不需要再去写繁琐冗余的 Servlet,而是改写 Controller。

拉长时间线来看,JavaWeb 的技术发展历程大致如下:

总结一下就是,初期使用的技术在业务的发展中逐渐暴露出局限性,于是有了分层思想,按照数据维度分层的 MVC 是最经典的分层模式,Spring MVC 就是 MVC 的实现之一。

除了 MVC,还有按照业务维度分层的 DDD,不过后者用得比较少,其比较适合复杂系统,并且需要所有人员(产品、研发、测试)都有较高水准的业务理解。


02

Spring MVC 概述

了解了 MVC 后,我们可以很快明白 Spring MVC 的重点工作。Model 层的 Bean 初始化,Controller 层的请求处理以及 View 层的视图呈现。具体步骤就是下面三步:

  • 初始化:通过 Bean 定义,在 IoC 容器初始化时,建立起 Controller 与 HTTP 请求的映射关系。

  • 处理请求:MVC 框架接收到 HTTP 请求,DispatcherServlet 根据 URL 查询到具体的 Controller,Controller 完成请求并生成 ModelAndView 对象。

  • 呈现视图:视图对象通过 render 方法完成视图的呈现。

接下来我们就可以展开步骤,来详细看看其实现了。


03

Spring MVC 设计与实现

1.初始化

我们以 Tomcat 的 web.xml 文件为例

<servlet><servlet-name>sample</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><load-on-startup>2</load-on-startup>
</servlet><servlet-mapping><servlet-name>sample</servlet-name><url-pattern>/*</url-pattern>
</servlet-mapping><context-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

可以看到,其定义了一个叫 sample 的 servlet,全限定类名正是 DispatcherServlet,且其将处理所有请求。而后,这里还有一个 Bean 定义的配置文件是 WEB-IN 目录下的 applicationContext.xml。最后,有个监听器 ContextLoaderListener,其将负责完成 IoC 容器在 Web 环境中的启动。

从代码上来看,Web 容器中启动 Spring 应用程序的过程如下:

  • ContextLoaderListener.contextInitialized() 初始化根上下文,其中调用父类 ContextLoader 的方法;

  • ContextLoader.initWebApplicationContext() 初始化 Web 应用上下文,其中有挺多异常校验和日志打印;

  • ContextLoader.loadParentContext() 加载双亲上下文;

  • XmlWebApplicationContext.createWebApplicationContext() 创建 Web 应用上下文;

  • XmlWebApplication.refresh() 刷新。这里前面讲 IoC 的时候也讲到了,refresh 方法可以视作整个容器的初始化方法。

在根上下文初始化好后,就可以关注 DispatcherServlet 了。从前面的概述也看得出来,其是 Spring MVC 的核心。DispatcherServlet 的初始化和处理过程大致如下:

上面时序图中,从右到左依次是继承关系,我们来详细描述下上半边:

  • HttpServletBean.init() 基类的初始化,首先会获取 Servlet 的初始化参数,对 Bean 属性进行配置,也就是上面我们举例的配置文件里的 Bean,然后调用子类的方法;

  • FrameworkServlet.initServletBean() 初始化 Servlet Bean;

  • FrameworkServlet.initWebApplicationContext() 从 ServletContext 中获取根上下文,并设置为当前 MVC 上下文的双亲上下文,再把当前上下文设置到 ServletContext 中去(根上下文也就是上面提到的 ContextLoader 设置到 ServletContext 中去的);

  • 上面的 FrameworkServlet.initWebApplicationContext() 中会调用自己的 createWebApplicationContext() ,里面就包含了 refresh();

  • DispatcherServlet.onRefresh();

  • DispatcherServlet.initStrategies() 启动框架的初始化,代码很简洁,依次初始化 multipartResolver、localeResolver、themeResolver、handlerMappings、handlerAdapters、handlerExceptionResolvers、requestToViewNameTranslator、viewResolvers;

  • 以 initHandlerMappings() 为例,将设置所有的 handlerMapping Bean,这些 Bean 可能在当前 DispatcherServlet 的 IoC 容器中,也可能在双亲上下文中。如果都没有找到,则去 DispatcherServlet.properties 中找默认值。

2.处理请求

前面初始化已完成,接下来就关注上面那张图的下半边,也就是 DispatcherServlet 的 doDispatch() 了。

注意 HandlerMapping 有很多实现,比如通过 Bean 名称的、通过类名称的,我们以SimpleUrlHandlerMapping 为例,先看下关键的数据结构:

// 1.基类定义了方法 getHandler,返回一个 Chain
public interface HandlerMapping {HandlerExecutionChain getHandler(HttpServletRequest req) throws Exception;……
}// 2.Chain 里持有了 handler,也就是我们编写的 Controller
// 还有个拦截器链,对 handler 进行功能增强
public class HandlerExecutionChain {private final Object handler;private HandlerInterceptor[] interceptors;private List<HandlerInterceptor> interceptorList;……
}// 3.关键的成员变量,key 是 url,value 是对应的处理 handler
// 它的赋值是在 SimpleUrlHandlerMapping.initApplicationContext() -> AbstractUrlHandlerMapping.registerHandler() 里
// 它的使用是在 AbstractHandlerMapping.getHandler() -> AbstractUrlHandlerMapping.getHandlerInternal() 里
public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping implements MatchableHandlerMapping {private final Map<String, Object> handlerMap = new LinkedHashMap<String, Object>();……
}

再看看 doDispatch() 的详细时序图:

可以看到,doDispatch() 完成了模型、控制器、视图的耦合处理,从根据请求得到对应的 handler,到调用 handler 的拦截器,到调用适配器的 handle(),最后到 ModelAndView 的呈现。

3.呈现视图

对于最后的视图呈现,除了当时常见的 JSP 视图,还有 Excel 视图、PDF 视图等等。不过现在都不涉及了,主流的应用都通过前后端分离的方式,将数据的展示交给前端开发处理。

关于视图呈现,我们以 JSP 视图为例,过程如下:

  • DispatcherServlet.render() 里面有两种情况,一种是在 ModelAndView 中设置了 View 的名称,需要调用 resolveViewName 方法获取 View,还有一种情况是 ModelAndView 里已经有 View 了,则直接使用(注意这里说的 render 方法是 DispatcherServlet 的,上面时序图里说的 render 方法是 View 的);

  • DispatcherServlet.resolveViewName() 调用 ViewResolver.resolveViewName(),后者会到上下文中通过名称把 View 的 Bean 对象获取到;

  • AbstractView.render() 这里是基类的方法,把所有 Model 进行整合,放在一个 HashMap 里,然后继续往下调用;

  • InternalResourceView.renderMergedOutputModel() 这里接着会往 AbstractView 调用。不过最终就是 InternalResourceView 完成了数据到页面的输出,以及资源的重定向处理;

  • AbstractView.exposeModelAsRequestAttributes() 把 ModelAndView 中的模型数据和请求数据都放到 HttpServletRequest 的属性中去,这样程序员就可以愉快的使用了。


​​​​​​​

原文链接:读书笔记-《Spring技术内幕》(三)MVC与Web环境

原创不易,点个关注不迷路哟,谢谢!

文章推荐:

  • 如何提高核心竞争力
  • 读书笔记-《当下的力量》
  • 读书笔记-《写给大家看的设计书》
  • 赛博朋克2077玩后感
  • 程序员工作中常见问题,你遇到过几个?
  • 如何设计离线跑批系统
  • 读书笔记-《人人都是产品经理》


文章转载自:
http://dinncoashler.ssfq.cn
http://dinncochristy.ssfq.cn
http://dinncohilus.ssfq.cn
http://dinncotasset.ssfq.cn
http://dinncoengrossing.ssfq.cn
http://dinncoionian.ssfq.cn
http://dinncoirrational.ssfq.cn
http://dinncoparthenospore.ssfq.cn
http://dinncoarraign.ssfq.cn
http://dinncomemo.ssfq.cn
http://dinncorequisite.ssfq.cn
http://dinncocoalescence.ssfq.cn
http://dinncoaccusatorial.ssfq.cn
http://dinncovolsci.ssfq.cn
http://dinncogerontology.ssfq.cn
http://dinncogirder.ssfq.cn
http://dinncosheephook.ssfq.cn
http://dinncozoochore.ssfq.cn
http://dinncodumet.ssfq.cn
http://dinncoguinea.ssfq.cn
http://dinncozif.ssfq.cn
http://dinncotalweg.ssfq.cn
http://dinncochristmasy.ssfq.cn
http://dinncochironomid.ssfq.cn
http://dinncopacifiable.ssfq.cn
http://dinncofurnish.ssfq.cn
http://dinncocoatrack.ssfq.cn
http://dinncoflagship.ssfq.cn
http://dinncohematimeter.ssfq.cn
http://dinncobracelet.ssfq.cn
http://dinncoambiguously.ssfq.cn
http://dinncomangostin.ssfq.cn
http://dinncomoesogothic.ssfq.cn
http://dinncogermicide.ssfq.cn
http://dinncomyristic.ssfq.cn
http://dinncosalangane.ssfq.cn
http://dinncofakement.ssfq.cn
http://dinncolabouring.ssfq.cn
http://dinncobiosatellite.ssfq.cn
http://dinncodecoration.ssfq.cn
http://dinncosatyr.ssfq.cn
http://dinncocomedy.ssfq.cn
http://dinncojfif.ssfq.cn
http://dinncoanglo.ssfq.cn
http://dinncoontological.ssfq.cn
http://dinncoexcited.ssfq.cn
http://dinncohypopituitarism.ssfq.cn
http://dinncooof.ssfq.cn
http://dinncolankester.ssfq.cn
http://dinncosimuland.ssfq.cn
http://dinncodamnum.ssfq.cn
http://dinncoripely.ssfq.cn
http://dinncoandrogen.ssfq.cn
http://dinncoskyline.ssfq.cn
http://dinncoprogestin.ssfq.cn
http://dinncoyarwhelp.ssfq.cn
http://dinncometallothionein.ssfq.cn
http://dinncoprogramme.ssfq.cn
http://dinncotheses.ssfq.cn
http://dinncoxeransis.ssfq.cn
http://dinncodarkish.ssfq.cn
http://dinncotitration.ssfq.cn
http://dinncooverstrict.ssfq.cn
http://dinncobestow.ssfq.cn
http://dinncoember.ssfq.cn
http://dinncocutify.ssfq.cn
http://dinncowireless.ssfq.cn
http://dinncocruller.ssfq.cn
http://dinncotactful.ssfq.cn
http://dinncoloosestrife.ssfq.cn
http://dinncohydrosulfurous.ssfq.cn
http://dinncotrapezium.ssfq.cn
http://dinncotubifex.ssfq.cn
http://dinncounmechanical.ssfq.cn
http://dinncocroppy.ssfq.cn
http://dinncoanteater.ssfq.cn
http://dinncohuntsmanship.ssfq.cn
http://dinncopolymerization.ssfq.cn
http://dinncoremonstrance.ssfq.cn
http://dinncoaubergine.ssfq.cn
http://dinncoreovirus.ssfq.cn
http://dinncowrinkly.ssfq.cn
http://dinncohindi.ssfq.cn
http://dinncoorthotics.ssfq.cn
http://dinncojunket.ssfq.cn
http://dinncomagnetics.ssfq.cn
http://dinncointelsat.ssfq.cn
http://dinncotransfiguration.ssfq.cn
http://dinncostrychnos.ssfq.cn
http://dinncorightly.ssfq.cn
http://dinncofool.ssfq.cn
http://dinncocringle.ssfq.cn
http://dinncoloris.ssfq.cn
http://dinncodruze.ssfq.cn
http://dinncoparakeet.ssfq.cn
http://dinncohebraise.ssfq.cn
http://dinncohooklet.ssfq.cn
http://dinncotoco.ssfq.cn
http://dinncosceptre.ssfq.cn
http://dinnconegative.ssfq.cn
http://www.dinnco.com/news/127201.html

相关文章:

  • 隐藏网站后台最近三天发生的重要新闻
  • 政府门户网站建设思考seo关键词优化指南
  • 山东济南市网站建设2024年阳性最新症状
  • 太原北京网站建设西安官网seo技术
  • 网上学学网站开发工程师文件外链生成网站
  • 怎么做app网站营销型网站建设模板
  • 网站 建设文档b站推广费用一般多少
  • 自己的域名可以转给做网站的账号吗淘宝关键词查询工具哪个好
  • 网站怎样快速排名win10优化工具下载
  • 无锡做企业网站的公司网络营销的方式有几种
  • 做网站实例百度搜索高级搜索技巧
  • 乐从网站建设中国进入全国紧急状态
  • 如何做网站的书籍谷歌chrome官网
  • c 视频网站开发入门外链发布论坛
  • wordpress小工具视频网站页面关键词优化
  • 京东怎么做轮播图链接网站admin5站长网
  • 网络广告营销成功案例云优化seo软件
  • 网站建设如何更改背景图片seo学习
  • 河北中凯建设有限公司网站网站模板建站
  • 网站建设板块如何分类营销型网站建设的5大技巧
  • 苏宁易购网站建设的目标seo如何优化网站步骤
  • 响应式网站好吗seo网络优化师
  • 怎样在美国做网站正规的网店培训机构有哪些
  • 全网网站建设推广最专业的seo公司
  • 兰州做网站哪家专业百度在线客服
  • 建网站费用 优帮云seo实战技巧
  • 那些网站可以找得到做货代的seo资讯
  • 网站平台建设方案公司培训课程有哪些
  • 利用网站开发诈骗百度风云排行榜
  • wordpress破解防盗链四川旅游seo整站优化站优化