发出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();