查阅Springboot文档,在SPRING MVC AUTO-CONFIGURATION
节点下对ViewResolver
等扩展条件进行了说明。
如果想要定制化一些功能,只需要重写这个组件,然后将它交给springboot,springboot会帮我们自动装配。
ViewResolver视图解析配置
1、文档查看路径
ViewResolver:ContentNegotiatingViewResolver->ViewResolver->resolveViewName->getCandidateViews、getBestView
2、配置代码
自定义
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
//将MyViewResolver放入Bean中
@Bean
public ViewResolver myViewResolver(){
return new MyViewResolver();
}
public static class MyViewResolver implements ViewResolver {
//重写resolveViewName方法
@Override
public View resolveViewName(String viewName, Locale locale) throws Exception {
return null;
}
}
}
3、测试组件是否放入Bean中
DispatcherServlet->doService->doDispatch,在浏览器中输入http:localhost:8080/