赞
踩
客户端通过RestTemplate发送请求,requestBody是一个复杂数据类型,通过嵌套多层MultiValueMap的方式组合服务端需要的数据类型。
HttpEntity requestBody = generateAddAllRequestBody(strategyJobs);
ResponseEntity responseEntity = this.restTemplate.postForEntity(jobAddAllUrl, requestBody, String.class); private HttpEntity generateAddAllRequestBody(List strategyJobs) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
MultiValueMap outerMap = new LinkedMultiValueMap<>();
for(StrategyJob strategyJob : strategyJobs) {
MultiValueMap map = new LinkedMultiValueMap();
map.add("jobGroup",strategyJob.getGroup());
map.add("jobDesc", strategyJob.getJobDesc());
map.add("executorRouteStrategy", "FIRST");
map.add("cronGen_display", strategyJob.getCron());
map.add("jobCron", strategyJob.getCron());
map.add("glueType", "BEAN");
map.add("executorHandler", strategyJob.getExecutorHandler());
map.add("executorBlockStrategy", "SERIAL_EXECUTION");
map.add("childJobId", "");
map.add("executorTimeout", 0);
map.add("executorFailRetryCount", 0);
map.add("author", strategyJob.getCreator());
map.add("alarmEmail", "");
map.add("executorParam", strategyJob.getStrategyId());
map.add("glueRemark", "GLUE代码初始化");
map.add("glueSource", "");
map.add("triggerStatus", 1);
if (strategyJob.getId() != null) {
map.add("id", strategyJob.getId());
}
outerMap.add(strategyJob.getKey(), map);
}
HttpEntity requestBody = new HttpEntity(outerMap, headers);
return requestBody;
}
服务端接收请求的时候,只能解析第一
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。