1、视图内容协商
交互流程:
1、ContentNegotiationConfigurer- - -关联- - ->ContentNegotiationManagerFactoryBean
2、ContentNegotiationConfigurer - - - 配置 - - ->ContentNegotiationStrategy 实现(PathExtensionContentNegotiationStrategy、ParameterContentNegotiationStrategy、FixedContentNegotiationStrategy、HeaderContentNegotiationStrategy、ServletPathExtensionContentNegotiationStrategy)
3、ContentNegotiationStrategy 实现 - - - 添加策略- - -> ContentNegotiationManagerFactoryBean
4、ContentNegotiationManagerFactoryBean - - - 创建- - -> ContentNegotiationManager
5、ContentNegotiationViewResolver- - - Bean 关联 - - - >ContentNegotiationManager
6、ContentNegotiationViewResolver - - - Bean关联 - - ->ViewResolver Bean 列表(InternalResourceViewResolver、ThymeleafViewResolver 、。。。)
7、Client - - - 请求- - ->DispatchServlet
8、DispatchServlet - - -解析View - - -> ContentNegotiationViewResolver
9、ContentNegotiationViewResolver - - - 策略匹配- - -> ViewResolver Bean 列表 (InternalResourceViewResolver、ThymeleafViewResolver 、。。。)
10、ContentNegotiationViewResolver - - - 最佳匹配View - - ->DispatchServlet
11、DispatchServlet - - - View渲染 - - -> Client
主要组件:
视图解析
ContentNegotiatingViewResolver
InternalResourceViewResolver
BeanNameViewResolver
ThymeleafViewResolver
配置策略
配置 Bean: WebMvcConfigurer
配置对象: ContentNegotiationConfigurer
策略管理
Bean: ContentNegotiationManager
FactoryBean : ContentNegotiationManagerFactoryBean
策略实现
ContentNegotiationStrategy
固定 MediaType : FixedContentNegotiationStrategy
"Accept" 请求头: HeaderContentNegotiationStrategy
请求参数: ParameterContentNegotiationStrategy
路径扩展名: PathExtensionContentNegotiationStrategy
2、多视图内容协商
视图处理器协商
ContentNegotiatingViewResolver
BeanNameViewResolver
InternalResourceViewResolver Content-Type : text/xml;charset=UTF-8
ThymeleafViewResolver Content-Type : text/html;charset=UTF-8
最佳 View 匹配规则
ViewResolver 优先规则
自定义 InternalResourceViewResolver
ThymeleafViewResolver
默认 InternalResourceViewResolver
MediaType 匹配规则
Accept 头策略
请求参数策略
3、视图组件自动装配
自动装配 Bean
视图处理器
InternalResourceViewResolver
BeanNameViewResolver
ContentNegotiatingViewResolver
ViewResolverComposite
ThymeleafViewResolver ( Thymeleaf 可用)
内容协商
ContentNegotiationManager
外部化配置
WebMvcProperties
WebMvcProperties.Contentnegotiation
WebMvcProperties.View