AbstractControllerUrlHandlerMapping类简介说明
下文讲述AbstractControllerUrlHandlerMapping类的简介说明,如下所示:
AbstractControllerUrlHandlerMapping的功能:
此类将实现Controller接口或注释了@Controller的bean作为Handler
并且可以通过设置excludedClasses和excludedPackages
将不包含的bean或不包含的包下的所有bean排除在外
determineUrlsForHandler()方法的功能
determineUrlsForHandler() 获取bean并完成beanName和beanClass的对应关系
@Override
protected String[] determineUrlsForHandler(String beanName) {
Class beanClass = getApplicationContext().getType(beanName);
//判断是不是支持的类型
if (isEligibleForMapping(beanName, beanClass)) {
//模板方法,在子类实现
return buildUrlsForHandler(beanName, beanClass);
}
else {
return null;
}
}
setIncludeAnnotatedControllers() 配置操作
public void setIncludeAnnotatedControllers(boolean includeAnnotatedControllers) {
this.predicate = (includeAnnotatedControllers ? new AnnotationControllerTypePredicate() : new ControllerTypePredicate());
}
public void setExcludedPackages(String... excludedPackages) {
this.excludedPackages = (excludedPackages != null) ? new HashSet(Arrays.aslist(excludedPackages)) : new HashSet();
}
public void setExcludedClasses(Class... excludedClasses) {
this.excludedClasses = (excludedClasses != null) ? new HashSet>(Arrays.asList(excludedClasses)) : new HashSet>();
}
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


