视图解析器在DispatcherServlet的resolveViewName方法中通过解析指定View名获取指定View
View view = viewResolver.resolveViewName(viewName, locale);
查看ViewResolver接口
public interface ViewResolver {
//解析指定名称的视图
View resolveViewName(String viewName, Locale locale) throws Exception;
}
此接口只有一个方法——解析指定名称的视图
1564055559703.pngInternalResourceViewResolver无resolveViewName方法的实现,此方法的实现在其祖父类AbstractCachingViewResolver中
查看AbstractCachingViewResolver的resolveViewName方法(看看如何根据指定名称解析视图)
public View resolveViewName(String viewName, Locale locale) throws Exception {
if (!isCache()) {
//不在缓存中,创建
return createView(viewName, locale);
}
else {
//从缓存中读取
//...省略
}
}
protected View createView(String viewName, Locale locale) throws Exception {
return loadView(viewName, locale);
}
protected abstract View loadView(String viewName, Locale locale) throws Exception;
AbstractCachingViewResolver使用了缓存技术,而视图的创建这一职责转移给了子类
网友评论