您的位置:首页 > 编程语言 > Java开发

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

2013-08-16 22:33 591 查看
实验室的项目用到了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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐