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

实验室的项目用到了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;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值