使用RestTemplate 远程调用,传递文件类型参数
- 类私有属性声明
@Value("${server.remoteIpPort}")
private String remoteIpPort;
@Resource
private RestTemplate restTemplate;
- 方法实现
@PostMapping("/uploadExcel")
@SuppressWarnings("unchecked")
public HttpResult uploadExcel(@RequestParam("file") MultipartFile multipartFile) {
Map<String, Object> resultMap = new HashMap<>();
File f = null;
try{
// 设置请求头
HttpHeaders headers = new HttpHeaders();
MediaType type = MediaType.parseMediaType("multipart/form-data");
headers.setContentType(type);
// 设置请求体,注意是LinkenMultiValueMap
MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
// 创建临时文件,用于远程调用参数传递
f =