ayugudu
V2EX  ›  Java

Spring boot 参数是怎样解析的呀

  •  
  •   ayugudu · Apr 15, 2022 · 3090 views
    This topic created in 1487 days ago, the information mentioned may be changed or developed.

    DataBinder 用于绑定对象 那 messagecovert 用于消息转换 ,两者的关联是什么呀 到底是怎样绑定的啊

    5 replies    2022-04-16 10:44:58 +08:00
    ayugudu
        1
    ayugudu  
    OP
       Apr 15, 2022
    个人的理解 MessageConvert:用于解析 request 中 数据的解析

    databinder:用于解决 request 中解析的数据 绑定到 所使用的接收对象
    ayugudu
        2
    ayugudu  
    OP
       Apr 15, 2022
    希望又老哥 给我讲解一下 原理
    ayugudu
        3
    ayugudu  
    OP
       Apr 15, 2022
    messageconvert 在返回参数 时也使用了 更像是 将另一种数据 转换成其他类型的
    ikas
        4
    ikas  
       Apr 15, 2022
    1.
    HttpMessageConverter, 是 spring web 特有的,其针对的是 http body 的解析,也就是你用 @RequestBody 的地方,就是用它


    2.
    DataBinder 用于给目标对象设置属性的接口,其实 spring 中通用的,不仅仅局限于 web, 而 WebDataBinder 继承自 DataBinder 顾名思义

    DataBinder 实现了 TypeConverter 接口,因为给目标属性设置 value 的时候需要转换到一致的类型

    TypeConverter 接口,其实现主要依赖 spring 提供的转换接口,主要有 PropertyEditorSupport 与 Converter<S, T>

    PropertyEditorSupport 继承自 jdk javabean 包中的 PropertyEditor,其主要针对字符转与其他类型的相互转换

    Converter<S, T>,这是 spring 中提供的任意 2 中类型转换的接口
    ayugudu
        5
    ayugudu  
    OP
       Apr 16, 2022
    @ikas 谢谢老哥
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1002 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 22:17 · PVG 06:17 · LAX 15:17 · JFK 18:17
    ♥ Do have faith in what you're doing.