Update 26.1.2. HttpMessageConverters.md

master
qibaoguang 2015-02-10 23:41:27 +08:00
parent 30926b5b93
commit dbc13986fa
1 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,22 @@
### 26.1.2. HttpMessageConverters
Spring MVC使用HttpMessageConverter接口转换HTTP请求和响应。合理的缺省值被包含的恰到好处out of the box例如对象可以自动转换为JSON使用Jackson库或XML如果Jackson XML扩展可用则使用它否则使用JAXB。字符串默认使用UTF-8编码。
如果需要添加或自定义转换器你可以使用Spring Boot的HttpMessageConverters类
```java
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
import org.springframework.context.annotation.*;
import org.springframework.http.converter.*;
@Configuration
public class MyConfiguration {
@Bean
public HttpMessageConverters customConverters() {
HttpMessageConverter<?> additional = ...
HttpMessageConverter<?> another = ...
return new HttpMessageConverters(additional, another);
}
}
```
任何在上下文中出现的HttpMessageConverter bean将会添加到converters列表你可以通过这种方式覆盖默认的转换器converters