问题描述:使用restTemplate请求其他项目数据,已知对应的接口返回为BaseResponse
code | int |
msg | String |
Data<Map<String,List<Object>>> | map集合 |
一开始使用
rest Template.postForObject(url,list,BaseResponse.class)进行返回,但是发现object的类型为hashMap类型,做类型转换的时候出现问题
解决方法:
JSONObject jSONObject=restTemplate.postForObject(url,list,JSONObject.class);
JSONObject data=jSONObject.getJSONObject("data");
map=JSON.parseObject(data.toString(),new TypeReference<Map<String,Object>>(){});
即可获得对应的map集合