spring converter-message 规则

时间:2023-03-09 05:17:09
spring converter-message 规则

spring 判断返回值使用哪个 converter 时,会执行两次converter 循环。。

第一次会根据 返回类型(converter的support方法) 和 mediaType 遍历所有converter(包含你自定义的和默认的8个)。判断所有符合的 mediaType.

然后根据你请求头中 Accept 。。 (例如text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8  其中q 是优先级) 。 然后找到符合条件的mediaType 中的优先级最高的。

然后再次遍历converter : 根据返回类型和mediaType 找到对应的converter..