Update How-to_ guides.md

master
qibaoguang 2015-03-26 00:09:22 +08:00
parent 326b632206
commit 0ba2b7d316
1 changed files with 16 additions and 0 deletions

View File

@ -488,6 +488,22 @@ GzipFilter可以使用`spring.http.gzip.*`属性进行配置。具体参考[Gzip
### Spring MVC
* 编写一个JSON REST服务
在Spring Boot应用中任何Spring `@RestController`默认应该渲染为JSON响应只要classpath下存在Jackson2。例如
```java
@RestController
public class MyController {
@RequestMapping("/thing")
public MyThing thing() {
return new MyThing();
}
}
```
只要MyThing能够通过Jackson2序列化比如一个标准的POJO或Groovy对象[localhost:8080/thing](http://localhost:8080/thing)默认响应一个JSON表示。有时在一个浏览器中你可能看到XML响应因为浏览器倾向于发送XML
响应头。
* 编写一个XML REST服务
* 自定义Jackson ObjectMapper
* 自定义@ResponseBody渲染