频道栏目
首页 > 资讯 > 其他 > 正文

RestTemplate 的一个使用样例

18-06-29        来源:[db:作者]  
收藏   我要投稿

使用exchange可以实现任何请求

一个样例

String fooResourceUrl = "http://localhost:8080/spring-rest/foos";
ClientHttpRequestFactory requestFactory = getClientHttpRequestFactory();
RestTemplate restTemplate = new RestTemplate(requestFactory);
HttpEntity request = new HttpEntity<>(new Foo("bar"));
ResponseEntity response = restTemplate.exchange(fooResourceUrl, HttpMethod.POST, request, Foo.class);
assertThat(response.getStatusCode(), is(HttpStatus.CREATED));
Foo foo = response.getBody();
assertThat(foo, notNullValue());
相关TAG标签
上一篇:Python基础语法学习之 and or 以及循环语句的基本使用
下一篇:React Native TextInput 输入框赋值没反应解决
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站