resttemplate使用记录1

使用resttemplate批量上传文件

MultiValueMap multiValueMap = new LinkedMultiValueMap();
for (String file : files) {
FileSystemResource resource = new FileSystemResource(new File(file));
multiValueMap.add(file, resource);
}
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
HttpEntity<MultiValueMap> body = new HttpEntity<>(multiValueMap, httpHeaders);

JSONArray jsonArray = restTemplate.postForObject(postUrl, body, JSONArray.class);


上一篇:RestTemplate


下一篇:白话SpringCloud | 第四章:服务消费者(RestTemple+Ribbon+Feign)