阅读导航
文章目录
01、概述
在使用springmvc时要配置哪些东西
- 前端控制器
- 控制器映射器和适配器
- 映射器
Map<Set<String>,Ob ject>
Set<String>
存放资源地@RequestMapper(value={“helle2”,”hello2”})
Object
存放方法对象和方法所有的对象的对- 执行方法
method.invoke(obj,args) Method
- 执行方法
- 适配器
@Controller
- 实现
Controller
接口 - 实现
HttpRequestHandler
的接口
- 映射器
- 视图解析器
InternalResourceViewResolver
- 文件上传的
- 拦截器
02、前端控制器的自动管理
2、找到DispatcherServletAutoConfiguration
3、注册
03、控制器的自动管理
就是自定义的controller
- 自动扫描
- 默认扫描启动类所在的包及其子包
- 如果不在启动类所有的包及其子包下面
- 要使用
@CompmentScan(basePackage={“com.sxt.controller”,”com.lsq.controller”})
- 要使用
04、视图解析器的自动管理
找到
WebMvcAutoConfiguration
@Bean
@ConditionalOnMissingBean
public InternalResourceViewResolver defaultViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix(this.mvcProperties.getView().getPrefix());
resolver.setSuffix(this.mvcProperties.getView().getSuffix());
return resolver;
}
@Bean
@ConditionalOnBean(View.class)
@ConditionalOnMissingBean
public BeanNameViewResolver beanNameViewResolver() {
BeanNameViewResolver resolver = new BeanNameViewResolver();
resolver.setOrder(Ordered.LOWEST_PRECEDENCE - 10);
return resolver;
}
@Bean
@ConditionalOnBean(ViewResolver.class)
@ConditionalOnMissingBean(name = "viewResolver", value = ContentNegotiatingViewResolver.class)
public ContentNegotiatingViewResolver viewResolver(BeanFactory beanFactory) {
ContentNegotiatingViewResolver resolver = new ContentNegotiatingViewResolver();
resolver.setContentNegotiationManager(beanFactory.getBean(ContentNegotiationManager.class));
// ContentNegotiatingViewResolver uses all the other view resolvers to locate
// a view so it should have a high precedence
resolver.setOrder(Ordered.HIGHEST_PRECEDENCE);
return resolver;
}
05、进入ContentNegotiatingViewResolver
总结
ContentNegotiatingViewResolver
他是一个视图解析器的收集器
只要IOC容器里面有实现有ViewResolver接口的对象都会被收集起来如ThymeleafViewResolver
06、文件上传和下载的视图解析器
1、找到
MultipartAutoConfiguration
2、找到MultipartProperties
07、静态资源的访问
-
classpath:resources/MATE-INF/resources
-
classpath:resources/resources
-
classpath:resources/static
-
classpath:resources/public
08、消息转化
找到
WebMvcAutoConfiguration
09、格式化转化
10、欢迎页面的配置
1、以前
web.xml
<welcome-file-list>
</webcome-file-list>
2、Springboot默认配置是
static/index.html
3、进入
WebMvcAutoConfiguration
其他
我的副业:觉得我的文章写得不错就支持一下我的副业吧
- 地址一:https://lsqstudy.github.io/post/d76a15aa112345.html
- 地址二:https://lsqstudy.gitee.io/post/d76a15aa112345.html
我的其他平台
作者做笔记不容易,请评个分吧!
- 如果觉得文章写行不错就点个 赞。✌
- 如果觉得写得好就 一键三连!✌✌✌
- 如果文章对你很有帮助,请 打赏。 💃💃💃💃💃