Manage springmvc components-front-end controllers, controller mappers and adapters, view parsers, file uploaders, interceptors || message conversion

Manage springmvc components

Overview

What to configure when using springmvc

  1. Front controller

  2. Controller mapper and adapter

    1. Mapper Map <Set <String>, Object>
      1. Set <String> storage resources   
        1. @RequestMapper(value={“helle2”,”hello2”})
      2. Object Objects that store method objects and all objects of methods
        1. Execution method method.invoke (obj, args) Method
    2. adapter  
      1. @Controller
      2. Implement the Controller interface
      3. Implement the interface of HttpRequestHandler
  3. View resolver

    InternalResourceViewResolver
  4. File upload

  5. Interceptor



Front-end controller automatic management

Find   WebMvcAutoConfiguration

找到  DispatcherServletAutoConfiguration

create

registered



Automatic management of the controller [that is, custom c ontroller]

Auto scan

| --The default scan starts all the packages and their sub-packages;

If it is not under all packages and subpackages of the startup class 

要使用 @CompomentScan(basePackage={“com.sxt.controller”,”com.bjsxt.controller”})



Automatic management of view resolvers

Find   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;
}

Enter ContentNegotiatingViewResolver

to sum up

ContentNegotiatingViewResolver  is a collector of view resolvers

As long as there are objects in the IOC container that implement the ViewResolver interface, they will be collected     as ThymeleafViewResolver



View parser for file upload and download

Find MultipartAutoConfiguration

Find MultipartProperties



Access to static resources

classpath:resources/MATE-INF/resources

classpath:resources/resources

classpath:resources/static

classpath:resources/public



Message conversion

Find   WebMvcAutoConfiguration

Format conversion



Welcome page configuration

Previously web.xml

<welcome-file-list>

</webcome-file-list>


Springboot default configuration is satic / i ndex.html

 

Enter WebMvcAutoConfiguration

Published 529 original articles · praised 115 · 90,000 views

Guess you like

Origin blog.csdn.net/qq_39368007/article/details/105621605