发出get请求,方式一

        String url = serverUrl+"/path/path?id={id}";
int i = restTemplate.getForObject(url,int.class,id);

发出get请求,方式二

        URI url= UriComponentsBuilder.fromUriString(serverUrl)
.path("/path/")
.queryParam("key", key)
.queryParam("key2",key2)
.queryParam("key3",key3)
.build()
.toUri();
return restTemplate.getForObject(url,String.class);

用spring restTemplate 发出post类型的表单请求

数据以键值对的方式进行传输,如:K=V&K=V

            MultiValueMap<String,Object> map = new LinkedMultiValueMap<>();
map.add("userid",userid);
map.add("password",password);
boolean flag = restTemplate.postForObject(loginUrl,map,boolean.class);

接收LIST<Object>类型的数据

ResponseEntity<List<WorkFlowURLMapping>> responseEntity = restTemplate.exchange(url, HttpMethod.GET,null,new ParameterizedTypeReference<List<WorkFlowURLMapping>>() {});
List<WorkFlowURLMapping> list = responseEntity.getBody();

  

spring restTemplate 用法的更多相关文章

  1. spring RestTemplate用法详解

    spring RestTemplate用法详解 spring 3.2.3 框架参考有说明 21.9 Accessing RESTful services on the Client

  2. (转载)spring RestTemplate用法详解

    前面介绍过spring的MVC结合不同的view显示不同的数据,如:结合json的view显示json.结合xml的view显示xml文档.那么这些数据除了在WebBrowser中用JavaScrip ...

  3. Spring RestTemplate介绍

    http://www.cnblogs.com/rollenholt/p/3894117.html RestTemplate 这篇文章打算介绍一下Spring的RestTemplate.我这边以前设计到 ...

  4. Spring RestTemplate 专题

    相同的参数(接口的入参json打印在日志了)在PostMan中返回预期的数据,但使用RestTemplate时去提示信息错误(参数中汉字).这种情况,搞得怀疑对RestTemplate的理解了使用Re ...

  5. RestTemplate用法

    RestTemplate 用法 RestTemplate简介 RestTemplate 是一个同步的web http客户端请求模板工具,spring框架做的抽象模板, 常见的http客户端请求工具有: ...

  6. Spring RestTemplate: 比httpClient更优雅的Restful URL访问, java HttpPost with header

    { "Author": "tomcat and jerry", "url":"http://www.cnblogs.com/tom ...

  7. Java Spring AOP用法

    Java Spring AOP用法 Spring AOP Java web 环境搭建 Java web 项目搭建 Java Spring IOC用法 spring提供了两个核心功能,一个是IoC(控制 ...

  8. Java Spring IOC用法

    Java Spring IOC用法 Spring IoC 在前两篇文章中,我们讲了java web环境搭建 和 java web项目搭建,现在看下spring ioc在java中的运用,开发工具为In ...

  9. How to Send an HTTP Header With Every Request With Spring RestTemplate

    In Know Which Apps Are Hitting Your Web Service, I showed how to write a servlet filter that enforce ...

随机推荐

  1. WC2018集训 吉老师的军训练

    WC2018集训 吉老师的军训练 #include<bits/stdc++.h> #define RG register #define IL inline #define _ 20000 ...

  2. BZOJ5251:[九省联考2018]劈配——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=5251 https://loj.ac/problem/2477  <-可以看数据 https: ...

  3. bzoj2326:[HNOI2011]数学作业(分段矩阵乘法)

    题目大意:输入n(n<=10^18)和m,将1~n的整数连起来模m输出,比如n=13则输出12345678910111213模m的数. 设f[i]为1~i整数连起来模m的数,i的位数为k,则有f ...

  4. apache出现You don't have permission to access / on this server. 提示

    今天在新的linux上跑原来的代码,使用的虚拟主机的模式进行操作.几个相关的网站放在一个文件里,想法是通过网站列出的目录进行相应的网站进行操作.一切设置完成后,在浏览器中运行出现在You don't ...

  5. django 给前端传递HTML内容

    django从view向template传递HTML字符串的时候,django默认不渲染此HTML,原因是为了防止这段字符串里面有恶意攻击的代码. 如果需要渲染这段字符串,需要在view里这样写: f ...

  6. mongo日常操作备忘

    修改 普通修改 插入数据: db.students.insert({ "name":"swrd", "age":32, "grad ...

  7. idea一些文件如.xml 文件搜索不到的解决方法

  8. [LeetCode] 19. Remove Nth Node From End of List ☆

    Given a linked list, remove the nth node from the end of list and return its head. For example, Give ...

  9. CodeBlocks wrong

    codeblocks官网 Q1. 中文乱码 系统是win,用的是codeblocks编辑器,指定的原文件编码是UTF-8 编译后运行,发现中文在控制台里显示全是乱码 A1: 对此有解决办法,通过给g+ ...

  10. python 基础--pip(转)

    感谢:http://www.cnblogs.com/csucat/p/4897695.html python需要用到一些其他的库,可以手动去各个库的官网下载,自己安装:也可以安装pip,使用pip可以 ...