resttemplate delete请求带参数
时间: 2023-09-15 17:16:30 浏览: 62
可以通过在URL中添加查询参数的方式,在DELETE请求中传递参数。具体的操作方式如下所示:
```java
RestTemplate restTemplate = new RestTemplate();
String url = "http://example.com/path?id={id}&name={name}";
restTemplate.delete(url, "123", "John");
```
其中,`{id}` 和 `{name}` 是查询参数的占位符,`"123"` 和 `"John"` 是实际的参数值。在实际的URL中,占位符会被替换为参数值,生成一个完整的URL,然后发送DELETE请求。
如果参数是一个对象,可以使用`UriComponentsBuilder`来构建URL,示例如下:
```java
RestTemplate restTemplate = new RestTemplate();
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://example.com/path")
.queryParam("id", "123")
.queryParam("name", "John");
String url = builder.toUriString();
restTemplate.delete(url);
```
在这个示例中,使用`UriComponentsBuilder`构建了一个带有查询参数的URL,然后发送DELETE请求。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)