springboot post请求和接收
请求:
RestTemplate restTemplate = new RestTemplate();
LinkedMultiValueMap body=new LinkedMultiValueMap();
body.add("map",dataService.runData());
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
HttpEntity httpEntity = new HttpEntity(body,headers);
restTemplate.exchange("http://localhost:9001/getData",HttpMethod.POST,httpEntity,String.class);
接收:
@PostMapping(value = "getData",produces = {"application/json;charset = utf-8"})
public void getData(@RequestBody LinkedMultiValueMap map){
try {
dataService.runData(map.get("map"));
}catch (Exception e){
e.printStackTrace();
}