“RestTemplate 总体介绍”的版本间的差异
跳到导航
跳到搜索
Jihongchang(讨论 | 贡献) |
Jihongchang(讨论 | 贡献) |
||
| (未显示同一用户的2个中间版本) | |||
| 第4行: | 第4行: | ||
也就是说导入 spring-boot-starter-web 的项目可以直接使用 RestTemplate。 | 也就是说导入 spring-boot-starter-web 的项目可以直接使用 RestTemplate。 | ||
| + | [[文件:Spring-boot-starter-web 包含 spring-web.png|无|缩略图|563x563像素]] | ||
在该类中主要针对6类请求方式封装了方法: | 在该类中主要针对6类请求方式封装了方法: | ||
| 第9行: | 第10行: | ||
!HTTP method | !HTTP method | ||
!RestTemplate methods | !RestTemplate methods | ||
| + | !差异 | ||
|- | |- | ||
|DELETE | |DELETE | ||
|delete | |delete | ||
| + | | | ||
|- | |- | ||
|GET | |GET | ||
|getForObject | |getForObject | ||
getForEntity | getForEntity | ||
| + | |字符流 | ||
| + | 不支持请求体 | ||
|- | |- | ||
|HEAD | |HEAD | ||
|headForHeaders | |headForHeaders | ||
| + | | | ||
|- | |- | ||
|OPTIONS | |OPTIONS | ||
|optionsForAllow | |optionsForAllow | ||
| + | | | ||
| + | |- | ||
| + | |POST | ||
| + | |postForLocation | ||
| + | postForObject | ||
| + | |字节流 | ||
| + | 支持请求体 | ||
| + | |- | ||
| + | |PUT | ||
| + | |put | ||
| + | | | ||
| + | |- | ||
| + | |any | ||
| + | |exchange | ||
| + | execute | ||
| + | | | ||
|} | |} | ||
2023年3月26日 (日) 05:21的最新版本
https://www.bilibili.com/video/BV1AN411Z7mx?p=7
RestTemplate 是 spring-web-xxx.jar 包中提供的 HTTP 协议实现类,与 HttpClient 功能类似。
也就是说导入 spring-boot-starter-web 的项目可以直接使用 RestTemplate。
在该类中主要针对6类请求方式封装了方法:
| HTTP method | RestTemplate methods | 差异 |
|---|---|---|
| DELETE | delete | |
| GET | getForObject
getForEntity |
字符流
不支持请求体 |
| HEAD | headForHeaders | |
| OPTIONS | optionsForAllow | |
| POST | postForLocation
postForObject |
字节流
支持请求体 |
| PUT | put | |
| any | exchange
execute |
