spring mvc 源代码笔记1--org.springframework.web.servlet.mvc.method

来源:互联网 发布:网络推广团队口号 编辑:程序博客网 时间:2024/06/06 23:07

实验室的项目用到了Spring MVC,决定看一下spring mvc 3.1.1的源代码,充充血。

首先先看了org.springframework.web.servlet工程下的org.springframework.web.servlet.mvc.method包。

RequestMappingInfo.java(主要存放HttpRequest信息,headers,patterns,consumes,produces,methods相关的)下有:

public RequestMappingInfo(PatternsRequestCondition patterns,
         RequestMethodsRequestCondition methods,
         ParamsRequestCondition params,
         HeadersRequestCondition headers,
         ConsumesRequestCondition consumes,
         ProducesRequestCondition produces,
         RequestCondition<?> custom) {
    this.patternsCondition = patterns != null ? patterns : new PatternsRequestCondition();
    this.methodsCondition = methods != null ? methods : new RequestMethodsRequestCondition();
    this.paramsCondition = params != null ? params : new ParamsRequestCondition();
    this.headersCondition = headers != null ? headers : new HeadersRequestCondition();
    this.consumesCondition = consumes != null ? consumes : new ConsumesRequestCondition();
    this.producesCondition = produces != null ? produces : new ProducesRequestCondition();
    this.customConditionHolder = new RequestConditionHolder(custom);
 }

自己倒是可能直接就赋值了!

get:判断入参是否为空!

 

@Override
 public boolean equals(Object obj) {
    if (this == obj) {
         return true;
    }
    if (obj != null && obj instanceof RequestMappingInfo) {
        RequestMappingInfo other = (RequestMappingInfo) obj;
            return (this.patternsCondition.equals(other.patternsCondition) &&
        this.methodsCondition.equals(other.methodsCondition) &&
        this.paramsCondition.equals(other.paramsCondition) &&
        this.headersCondition.equals(other.headersCondition) &&
        this.consumesCondition.equals(other.consumesCondition) &&
        this.producesCondition.equals(other.producesCondition) &&
        this.customConditionHolder.equals(other.customConditionHolder));
    }
     return false;
 }

override equals方法时,也用到了<<java核心技术里面>>提到的过程。

在这个类里面,页=也重写了hashCode(),看到用了31,防止hash冲突。

get:31是素数;31*N可以变成N<<5-N且5bit;

原创粉丝点击