使用MultiValueMap<String, Object> convertVars = new LinkedMultiValueMap()。
1.RestTemplate發起調用
@Service
public class TestService {
private RestTemplate restTemplate = new RestTemplate();
private String url = "http://localhost:8080/getTestData";
String SendStringArray() {
Map<String, String> orgNames = new HashMap<>();
String[] allIdArray = new String[] {"id1", "id2"};
MultiValueMap<String, Object> convertVars = new LinkedMultiValueMap();
convertVars.add("ids", allIdArray);
return restTemplate.postForObject(url, convertVars, String.class);
}
}
2.Controller層接收請求
@Controller
public class TestController {
@PostMapping("/getTestData")
@ResponseBody
public String[] getData(@RequestParam("ids") String [] ids){
return ids;
}
}