https://www.cnblogs.com/lijinyu08/p/14613902.html

  1. Spring MVC Auto-configuration
  2. // Spring Boot为Spring MVC提供了自动配置,它可以很好地与大多数应用程序一起工作。
  3. Spring Boot provides auto-configuration for Spring MVC that works well with most applications.
  4. // 自动配置在Spring默认设置的基础上添加了以下功能:
  5. The auto-configuration adds the following features on top of Springs defaults:
  6. // 包含视图解析器
  7. Inclusion of ContentNegotiatingViewResolver and BeanNameViewResolver beans.
  8. // 支持静态资源文件夹的路径,以及webjars
  9. Support for serving static resources, including support for WebJars
  10. // 自动注册了Converter:
  11. // 转换器,这就是我们网页提交数据到后台自动封装成为对象的东西,比如把"1"字符串自动转换为int类型
  12. // Formatter:【格式化器,比如页面给我们了一个2019-8-10,它会给我们自动格式化为Date对象】
  13. Automatic registration of Converter, GenericConverter, and Formatter beans.
  14. // HttpMessageConverters
  15. // SpringMVC用来转换Http请求和响应的的,比如我们要把一个User对象转换为JSON字符串,可以去看官网文档解释;
  16. Support for HttpMessageConverters (covered later in this document).
  17. // 定义错误代码生成规则的
  18. Automatic registration of MessageCodesResolver (covered later in this document).
  19. // 首页定制
  20. Static index.html support.
  21. // 图标定制
  22. Custom Favicon support (covered later in this document).
  23. // 初始化数据绑定器:帮我们把请求数据绑定到JavaBean中!
  24. Automatic use of a ConfigurableWebBindingInitializer bean (covered later in this document).
  25. /*
  26. 如果您希望保留Spring Boot MVC功能,并且希望添加其他MVC配置(拦截器、格式化程序、视图控制器和其他功能),则可以添加自己
  27. 的@configuration类,类型为webmvcconfiguer,但不添加@EnableWebMvc。如果希望提供
  28. RequestMappingHandlerMapping、RequestMappingHandlerAdapter或ExceptionHandlerExceptionResolver的自定义
  29. 实例,则可以声明WebMVCregistrationAdapter实例来提供此类组件。
  30. */
  31. If you want to keep Spring Boot MVC features and you want to add additional MVC configuration
  32. (interceptors, formatters, view controllers, and other features), you can add your own
  33. @Configuration class of type WebMvcConfigurer but without @EnableWebMvc. If you wish to provide
  34. custom instances of RequestMappingHandlerMapping, RequestMappingHandlerAdapter, or
  35. ExceptionHandlerExceptionResolver, you can declare a WebMvcRegistrationsAdapter instance to provide such components.
  36. // 如果您想完全控制Spring MVC,可以添加自己的@Configuration,并用@EnableWebMvc进行注释。
  37. If you want to take complete control of Spring MVC, you can add your own @Configuration annotated with @EnableWebMvc.

ContentNegotiatingViewResolver - 视图解析器