springmvc中的resolveView(视图解析器)

来源:互联网 发布:it专业学校排名 编辑:程序博客网 时间:2024/06/05 14:48
视图解析器接口只有一个方法,就是根据名称解析出视图信息(一个视图对象View)
采用的是模板模式  抽象模板类 AbstractCachingViewResolver  主要处理缓存,如果视图对象在缓存中有,则从缓存中取,如果没有则创建
public View resolveViewName(String viewName, Locale locale) throws Exception {
if (!isCache()) {
return createView(viewName, locale);
}
else {
Object cacheKey = getCacheKey(viewName, locale);
View view = this.viewAccessCache.get(cacheKey);
if (view == null) {
synchronized (this.viewCreationCache) {
view = this.viewCreationCache.get(cacheKey);
if (view == null) {
// Ask the subclass to create the View object.
view = createView(viewName, locale);
if (view == null && this.cacheUnresolved) {
view = UNRESOLVED_VIEW;
}
if (view != null) {
this.viewAccessCache.put(cacheKey, view);
this.viewCreationCache.put(cacheKey, view);
if (logger.isTraceEnabled()) {
logger.trace("Cached view [" + cacheKey + "]");
}
}
}
}
}
return (view != UNRESOLVED_VIEW ? view : null);
}
}
其中 createView 是抽象方法,在各个子类中去分别实现

1 0
原创粉丝点击