• Spring MVC的handlermapping之SimpleUrlHandlerMapping初始化


    前面信息同BeanNameUrlHandlerMapping,这里不再过多分析,详情请看 : Spring MVC的handlermapping之BeanNameUrlHandlerMapping初始化

    同样先上类图:

    可以看到SimpleUrlHandlerMapping是直接继承AbstractUrlHandlerMapping的

     1 public class SimpleUrlHandlerMapping extends AbstractUrlHandlerMapping {
     2     private final Map<String, Object> urlMap = new HashMap(); //用来保存url和handler的映射关系。
     3 
     4     public SimpleUrlHandlerMapping() {
     5     }
     6 
     7     public void setMappings(Properties mappings) { //通过spring自动注入,mapping属性值
     8         CollectionUtils.mergePropertiesIntoMap(mappings, this.urlMap);
     9     }
    10 
    11     public void setUrlMap(Map<String, ?> urlMap) { //通过spring自动注入,urlMap的值
    12         this.urlMap.putAll(urlMap);
    13     }
    14 
    15     public Map<String, ?> getUrlMap() {
    16         return this.urlMap;
    17     }
    18 
    19     public void initApplicationContext() throws BeansException { //重写方法,自己搞定注册处理器逻辑
    20         super.initApplicationContext();
    21         this.registerHandlers(this.urlMap);
    22     }
    23 
    24     protected void registerHandlers(Map<String, Object> urlMap) throws BeansException {
    25         String url;
    26         Object handler;
    27         if (urlMap.isEmpty()) {
    28             this.logger.warn("Neither 'urlMap' nor 'mappings' set on SimpleUrlHandlerMapping");
    29         } else { //遍历map,对url和handler进行合法性修补,最后调用父类进行注册处理器
    30             for(Iterator i$ = urlMap.entrySet().iterator(); i$.hasNext(); this.registerHandler(url, handler)) {
    31                 Entry<String, Object> entry = (Entry)i$.next();
    32                 url = (String)entry.getKey();
    33                 handler = entry.getValue();
    34                 if (!url.startsWith("/")) {
    35                     url = "/" + url;
    36                 }
    37 
    38                 if (handler instanceof String) {
    39                     handler = ((String)handler).trim();
    40                 }
    41             }
    42         }
    43 
    44     }
    45 }
  • 相关阅读:
    (转)sqlite3生成lib遇到的问题
    C++中的static
    static int和static final int的区别
    用static关键字修饰类
    Shell脚本的编写
    linux定时任务的设置 crontab 配置指南
    s3cmd的安装与配置
    s3cmd的安装与使用
    -Dmaven.multiModuleProjectDirectory system propery is not set.
    maven 环境搭建 Myeclipse配置
  • 原文地址:https://www.cnblogs.com/haoerlv/p/8668025.html
Copyright © 2020-2023  润新知