随笔分类 - springmvc
摘要:本文主要讲解如何使用Spring MVC4搭建RestFul Web service。我们新建一个进行CRUD操作的controller,使用http方法的POST、GET、PUT、DELETE来区分新建、查询、修改、删除。这个rest service使用json进行数据传输。我们使用CrossOrigin来解决跨域问题。
阅读全文
摘要:spring MVC cors跨域实现源码解析。
CorsConfiguration 具体封装跨域配置信息的pojo。
CorsConfigurationSource request与跨域配置信息映射的容器。
CorsProcessor 具体进行跨域操作的类。
阅读全文
摘要:HandlerMethod及子类主要用于封装方法调用相关信息,子类还提供调用,参数准备和返回值处理等职责.
阅读全文
摘要:HandlerMethodArgumentResolver主要负责执行handler前参数准备工作.
接口定义supportsParameter和resolveArgument.主要分为 类型
阅读全文
摘要:ModelFactory是用来维护Model.主要两个职责:初始化model;处理器执行后将model中相应的参数同步到SessionAttributes中
阅读全文
摘要:使用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处理器,并添加拦截器.
实现上,经典的接口+抽象类+具体算法实现.
阅读全文
摘要:使用@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号