RestTemplate
在使用 RestTemplate
时,通过map传参,遇到传不了参的问题
- 对于get请求,必须在请求的url中添加
?a={a}
,参数为对应的map的key
RestTemplate restTemplate = new RestTemplate();
String url = "https://restapi.amap.com/v3/weather/weatherInfo?key={key}&city={city}";
Map map = new HashMap();
map.put("key","4d6ab733dcfed0e82806b9a97ff602ff");
map.put("city","330100");
JSONObject forObject = restTemplate.getForObject(url, JSONObject.class, map);
- 对于post请求
1、调用postForObject方法 2、使用postForEntity方法 3、调用exchange方法
postForObject和postForEntity方法的区别主要在于可以在postForEntity方法中设置header的属性,当需要指定header的属性值的时候&#