02 2016 档案
摘要:使用SpringMVC开发时,可以使用@SessionAttributes注解缓存信息.这样业务开发时,就不需要一次次手动操作session保存,读数据.
SessionAttributesHanlder在初始化时扫描类里的方法,找出@SessionAttributes注解,并解析,然后直接保存到attributeNames和attributeTypes中,再更新knownAttributeNames.
保存的话,也可以在后期storeAttributes和isHandlerSessionAttribute进行.
在读取,清除时,都是以knownAttributeNames为索引,然后委托SessionAttributeStore处理.
阅读全文
摘要:HandlerAdapter在处理请求时上下文数据的传递工作是由ModelAndViewContainer负责的.
就是记录HandlerMethodArgumentResolver 和 HandlerMethodReturnValueHandler 在处理handler时 使用的模型model和视图view相关信息.
同时兼顾@SessionAttributes和redirect的情况.
阅读全文
摘要:SpringMVC进行请求分发到不同的处理器后,需要使用HandlerAdapter来准备参数,调用执行,封装返回值.RequestMappingHandlerAdapter是处理最复杂,使用最普遍的.
这边主要是分析RequestMappingHandlerAdapter初始话:注解解析器初始化注册;返回值处理类初始化;全局注解@ControllerAdvice内容读取并缓存.
阅读全文
摘要:HandlerMapping将url分发到对应的handler处理器,并添加拦截器.
实现上,经典的接口+抽象类+具体算法实现.
阅读全文
摘要:ant匹配规则;PathMatcher接口;通过测试用例看AntPathMatcher的使用
阅读全文
摘要:使用@RequestMapping注解时,配置的信息最后都设置到了RequestMappingInfo中.
RequestMappingInfo封装了PatternsRequestCondition,RequestMethodsRequestCondition,ParamsRequestCondition等,所以自己不干活,所有的活都是委托给具体的condition处理.
阅读全文
摘要:ConsumesRequestCondition 处理请求的提交内容类型(media-Type),例如application/json, text/html.
核心是MediaType和MediaTypeExpression接口.
阅读全文
摘要:@RequestMapping注解对应的条件匹配实现解读.
基础实现类分别实现content Type,请求头,request parameter,value(url),http method的匹配规则.
使用CompositeRequestCondition,RequestMappingInfo,RequestConditionHolder进行封装使用
阅读全文
摘要:AbstractHandlerMethodMapping实现接口getHandlerInternal,定义查找流程
RequestMappingInfoHandlerMapping根据RequestMappingInfo,细化匹配条件,并在匹配不到情况下,顽强的使用RequestCondition一再尝试匹配
虽然 RequestMappingHandlerMapping是受益方,但在这边什么都没做(就是在初始化时,根据@Controller,@RequestMapping注解生成RequestMappingInfo;并根据这两个注解判断是否目标Handler 实现isHandler)
阅读全文
摘要:初始化时,3个类的大致分工如下:
AbstractHandlerMethodMapping定义整个算法流程;
RequestMappingInfoHandlerMapping提供匹配条件RequestMappingInfo的解析处理;
RequestMappingHandlerMapping根据@RequestMapping注解生成 RequestMappingInfo,同时提供isHandler实现
阅读全文
摘要:AbstractHandlerMapping实现HandlerMapping接口定的getHandler 1. 提供getHandlerInternal模板方法给子类实现 2. 如果没有获取Handler,则使用默认的defaultHandler 3. 如果handler是string类型,从con
阅读全文
摘要:AbstractDetectingUrlHandlerMapping是通过扫描方式注册Handler,收到请求时由AbstractUrlHandlerMapping的getHandlerInternal进行分发.
阅读全文
摘要:SimpleUrlHandlerMapping只是参与Handler的注册,请求映射时由AbstractUrlHandlerMapping搞定.
阅读全文

浙公网安备 33010602011771号