添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
儒雅的火腿肠  ·  react.js - 'import' ...·  2 年前    · 
风流的板栗  ·  使用 Maven/Jenkins/Git ...·  2 年前    · 
坏坏的柿子  ·  Cannot find the file ...·  2 年前    · 
奔放的黄瓜  ·  java - How to receive ...·  2 年前    · 

前言

在使用​ ​RestTemplate​ ​的getForObject()方法时一直报错,原来是因为使用map传参需要固定RestTemplate访问的url格式。比如我想携带appId和appKey这两个参数,就得在url里面显示声明出来,特此记录一下

解决

RestTemplate restTemplate = null;
InfoResponse response = null;

restTemplate = GenericObjectPoolUtils.borrowObject(RestTemplate.class);

Map<String, String> hashMap = new HashMap<>(5);
hashMap.put("appId", appId);
hashMap.put("appKey", appKey);

response = restTemplate.getForObject(
"http://localhost:8083/api/getinfo?appId={appId}&appKey={appKey}"
InfoResponse.class, hashMap
);