# 16.1.2　Spring 是如何支持 REST 的

Spring 很早就有导出 REST 资源的需求。从 3.0 版本开始，Spring 针对 Spring MVC 的一些增强功能对 REST 提供了良好的支持。当前的 4.0 版本中，Spring 支持以下方式来创建 REST 资源：

* 控制器可以处理所有的 HTTP 方法，包含四个主要的 REST 方法：GET、PUT、DELETE 以及 POST。Spring 3.2 及以上版本还支持 PATCH 方法；
* 借助 @PathVariable 注解，控制器能够处理参数化的 URL（将变量输入作为 URL 的一部分）；
* 借助 Spring 的视图和视图解析器，资源能够以多种方式进行表述，包括将模型数据渲染为 XML、JSON、Atom 以及 RSS 的 View 实现；
* 可以使用 ContentNegotiatingViewResolver 来选择最适合客户端的表述；
* 借助 @ResponseBody 注解和各种 HttpMethodConverter 实现，能够替换基于视图的渲染方式；
* 类似地，@RequestBody 注解以及 HttpMethodConverter 实现可以将传入的 HTTP 数据转化为传入控制器处理方法的 Java 对象；
* 借助 RestTemplate，Spring 应用能够方便地使用 REST 资源。

本章中，我们将会介绍 Spring RESTful 的所有特性，首先介绍如何借助 Spring MVC 生成资源。然后在 16.4 小节中，我们会转向 REST 的客户端，看一下如何使用这些资源。那么，就从了解 RESTful Spring MVC 控制器是什么样子开始吧。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://potoyang.gitbook.io/spring-in-action-v4/di-16-zhang-shi-yong-spring-mvc-chuang-jian-rest-api/untitled-4/untitled.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
