一、以下是springboot对springMVC的默认配置
- Inclusion of ContentNegotiatingViewResolver and BeanNameViewResolver beans.
- 自动配置了ViewResolver(视图解析器:根据方法的返回值得到视图对象(View),视图对象决定如何
渲染(转发?重定向?))
- 自动配置了ViewResolver(视图解析器:根据方法的返回值得到视图对象(View),视图对象决定如何
- Support for serving static resources, including support for WebJars (see below).静态资源文件夹路
径,webjars - Static index.html support静态首页访问
- Custom Favicon support (see below). favicon.ico
- 自动注册了 of Converter , GenericConverter , Formatter beans.
- Support for HttpMessageConverters (see below)
- Converter:转换器; public String hello(User user):类型转换使用Converter
- Formatter 格式化器; 2017.12.17===Date;
- Automatic registration of MessageCodesResolver (see below).定义错误代码生成规则
- Automatic use of a ConfigurableWebBindingInitializer bean (see below).
我们可以配置一个ConfigurableWebBindingInitializer来替换默认的;(添加到容器)
PS:以上默认配置都可以自己进行配置来替换修改
二、配置类(@Configuration)
既保留了所有的自动配置,也能用我们扩展的配置;
//使用WebMvcConfigurerAdapter可以来扩展SpringMVC的功能
@Configuration
public class MyMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
// super.addViewControllers(registry);
//浏览器发送 /atguigu 请求来到 success
registry.addViewController("/atguigu").setViewName("success");
}
}
PS:若添加了@EnableWebMvc,则删除所有的自动配置。只使用我们扩展的配置。