> For the complete documentation index, see [llms.txt](https://potoyang.gitbook.io/spring-in-action-v5/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://potoyang.gitbook.io/spring-in-action-v5/di-7-zhang-tiao-yong-rest-fu-wu/7.1-shi-yong-resttemplate-tiao-yong-rest-duan-dian/7.1.2-qing-qiu-put-zi-yuan.md).

# 7.1.2 请求 PUT 资源

对于发送 HTTP PUT 请求，RestTemplate 提供 put() 方法。put() 的所有三个重载方法都接受一个将被序列化并发送到给定 URL 的对象。至于 URL 本身，可以将其指定为 URI 对象或 String。与 getForObject() 和 getForEntity() 类似，URL 变量可以作为变量参数列表或 Map 提供。

假设想要用来自一个新的 Ingredient 对象的数据来替换配料资源。下面的代码应该可以做到这一点：

```java
public void updateIngredient(Ingredient ingredient) {
    rest.put("http://localhost:8080/ingredients/{id}",
            ingredient,
            ingredient.getId());
}
```

这里 URL 以 String 的形式给出，并有一个占位符，该占位符由给定的 Ingredient 对象的 id 属性替换。要发送的数据是 Ingredient 对象本身。put() 方法返回 void，因此不需要处理返回值。
