09【掌握】管理springmvc组件

阅读导航

跳转到总目录

01、概述

在使用springmvc时要配置哪些东西

  1. 前端控制器
  2. 控制器映射器和适配器
    • 映射器 Map<Set<String>,Ob ject>
      • Set<String> 存放资源地
        • @RequestMapper(value={“helle2”,”hello2”})
      • Object 存放方法对象和方法所有的对象的对
        • 执行方法 method.invoke(obj,args) Method
    • 适配器
      • @Controller
      • 实现Controller接口
      • 实现HttpRequestHandler的接口
  3. 视图解析器
    • InternalResourceViewResolver
  4. 文件上传的
  5. 拦截器

02、前端控制器的自动管理

2、找到DispatcherServletAutoConfiguration

3、注册

03、控制器的自动管理

就是自定义的controller

  1. 自动扫描
    • 默认扫描启动类所在的包及其子包
  2. 如果不在启动类所有的包及其子包下面
    • 要使用@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、静态资源的访问

  1. classpath:resources/MATE-INF/resources

  2. classpath:resources/resources

  3. classpath:resources/static

  4. classpath:resources/public

08、消息转化

找到WebMvcAutoConfiguration

09、格式化转化

10、欢迎页面的配置

1、以前web.xml

<welcome-file-list>

</webcome-file-list>

2、Springboot默认配置是static/index.html

3、进入WebMvcAutoConfiguration

其他

我的副业:觉得我的文章写得不错就支持一下我的副业吧

我的其他平台

作者做笔记不容易,请评个分吧!

  • 如果觉得文章写行不错就点个 。✌
  • 如果觉得写得好就 一键三连!✌✌✌
  • 如果文章对你很有帮助,请 打赏。 💃💃💃💃💃
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员卖剩鸭

喜欢就点赞,疼爱就打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值