-
java入门之RestTemplate + okhttp 实现远程调用
1. 添加依赖
<!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.3.1</version>
</dependency>
2. 声明 RestTemplate
@Component
public class WebConfig {
/**
* 基于OkHttp3配置RestTemplate
* @return
*/
@Bean
public RestTemplate restTemplate() {
return new RestTemplate(new OkHttp3ClientHttpRequestFactory());
}
}
3. 测试controller
@RestController
public class RestTemplateController {
@Autowired
private RestTemplate restTemplate;
@GetMapping("/testRestTemplate")
public GraceJSONResult testRestTemplate(Model model) {
ResponseEntity<IMOOCJSONResult> responseEntity =
restTemplate.getForEntity("http://localhost:8001/article/queryIndexArticleList?page=0&pageSize=10", IMOOCJSONResult.class);
Map result = (Map)responseEntity.getBody().getData();
return GraceJSONResult.ok(result);
}
}
栏目列表
最新更新
基于JieBaNet+Lucene.Net实现全文搜索
C#取视频某一帧图片
Jwt身份验证
在Asp.Net Core MVC 3.0 视图运行时编译
C# SendAysnc 超时
RSA 登陆加密与解密
2d图片依次排列在屏幕中间(SpriteRendere
C#集合中根据多个字段分组 group by linq表达
浅浅的叙WPF之数据驱动与命令
C# -- 优先获取电脑C盘之外的磁盘来保存数
.Net Standard(.Net Core)实现获取配置信息
Linux PXE + Kickstart 自动装机
Shell 编程 基础
Shell 编程 条件语句
CentOS8-网卡配置及详解
Linux中LVM逻辑卷管理
1.数码相框-相框框架分析(1)
Ubuntu armhf 版本国内源
Linux中raid磁盘阵列
搭建简易网站
Dubbo(五):深入理解Dubbo核心模型Invok
vfp教程之VFP与Excel交互编程
vfp教程之在VFP中实现跟变式组合框及椭圆
SQL SERVER查询数据库所有表的大小,按照记
使用 SQL 服务器时,"评估期已过期"错
sql server无法连接本地服务器
使用sql语句创建表
VB操作Access数据库小记 ————————
access数据库远程连接
java web操作Access数据库