MappingJackson2HttpMessageConverter的学习

<mvc:annotation-driven >
<mvc:message-converters register-defaults="true">
<bean class="org.springframework.http.converter.json.EncryptJackson2HttpMessageConverter"/>
</mvc:message-converters>

</mvc:annotation-driven>

继承MappingJackson2HttpMessageConverter重写read等方法

spring提供了HttpMessageConverter转换器,默认加载了MappingJackson2HttpMessageConverter(json-->Object),只需配置@RequestBody 即可使用

注册的类已经变成了RequestMappingHandlerMapping和 RequestMappingHandlerAdapter

RequestMappingHandlerAdapter(注册参数解析器@PathVariable、HttpServletRequest等)



RequestMappingHandlerMapping




1. getApplicationContext().getType(beanName)
--->class com.dimeng.p2p.common.exception.ExceptionHandler
2. isHandler(Class<?> beanType)
(AnnotationUtils.findAnnotation(beanType, Controller.class) //重载了许多方法
判断类里面是否有Controller或RequestMapping注解

3.detectHandlerMethods(final Object handler)
(1) 反射得到相应的类
Class<?> handlerType = handler.getClass()
final Class<?> userType = ClassUtils.getUserClass(handlerType);
(2)得到类中方法的集合
Set<Method> methods = HandlerMethodSelector.selectMethods()
将RequestMapping注解转换为 RequestMappingInfo实体类
-->{[/{v}/invest],methods=[POST],produces=[application/json;charset=utf-8]}
RequestMappingInfo.combine(RequestMappingInfo other)//合并类型和方法级的请求映射,返回新的请求映射信息实例
ReflectionUtils.doWithMethods(Class<?> clazz, MethodCallback mc, MethodFilter mf)
new ReflectionUtils.MethodCallback(){ //抽象方法调接口 (每个action都会这样调用)
实现dowith()方法
}
(3)遍历方法
新建HandlerMethod实体类
将mapping与HandlerMethod对应关系放在handlerMethods的map中
将pattern与mapping放在urlMap中

4.handlerMethodsInitialized(Map<T, HandlerMethod> handlerMethods)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值