restTemplate Not enough variable values availabel

用 Spring RestTemplate 請求URL爲"http://dffffff/fdsa?queryParam={\"fds\":\"www\"}"時報Not enough variable values availabel異常,其根本原因是RestTemplate認爲大括號{…}在給定的URL作爲一個URI變量佔位符和試圖取代他們,


可用queryParam={queryParam}替代


Map<String,Object> params = new HashMap<>();

if(!StringUtils.isEmpty(mobile))
   params.put("mobile", mobile);
if(!StringUtils.isEmpty(userName))
   params.put("name", userName);
if(!StringUtils.isEmpty(email)){
   params.put("email", email);

String queryParam = JSONObject.valueToString(params);

ResponseEntity<PSResponseData> entity = restTemplate.exchange(Constants.PS_WEB_URL + "esb/query/view?serviceCode=2001&consumerCode=10015&queryParam={queryParam}", HttpMethod.GET, null, PSResponseData.class,queryParam);



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章