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();
}

posted @ 2020-10-19 12:34  _Lawrence  阅读(840)  评论(0编辑  收藏  举报