服务提供方
@RequestMapping("/test4")
@ResponseBody
public Map<String,Object> getString4(@RequestBody Data data) {
System.out.println("resp2:");
System.out.println("resp2:"+data.toString());
Map<String,Object> map = new HashMap<String, Object>();
map.put("code", 200);
map.put("message", "成功");
return map;
}
实体类Data
一定要有无参的构造方法,否则会报结构对不上的错
package com.pp.entity;
import java.io.Serializable;
/**
* @Author Bruce
* @Date 2015年7月11日
* @Comments
*/
public class Data implements Serializable {
private static final long serialVersionUID = -8660197629749596025L;
private Object data;
public Data() {
super();
}
public Data(Object data) {
super();
this.data = data;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
@Override
public String toString() {
return "Data [data=" + data + "]";
}
}
服务调用方
@Scheduled(fixedRate = 1000*3*5)
@Async
public void getInAndOutParkingInfoByIsAddeda() {
Resp2 resp2 = parkingApiService.getInAndOutParkingInfoByIsAdded();
Resp3 resp3 = new Resp3(resp2.getData());
if(resp2.getData()!=null) {
//把resp推送给其它接口
RestTemplate restTemplate = new RestTemplate();
// String url = "http://61.150.12.244:9851/gjdd_xiongan/carParkControl/carDataRepair";
String url = "http://localhost:7008/openWork/user/test4";
ResponseEntity<Map> map = restTemplate.postForEntity(url, resp3, Map.class);
System.out.println("message:"+map.getBody().get("message"));
}
}