spring RestTemplate 实例(NameValuePair)
第一种:
public List<NameValuePair> getThirdsysPermissionRest(String url,ThirdsysFuncpDTO thirdsysFuncpDTO){ RestTemplate restTemplate = new RestTemplate(); // 查询条件 HttpEntity<ThirdsysFuncpDTO> requestEntity = new HttpEntity<ThirdsysFuncpDTO>( thirdsysFuncpDTO); // 查询结果 ResponseEntity<List> result; // 通过rest的post方法取得数据 result = restTemplate.postForEntity(url, requestEntity,List.class); // 结果内容 List<NameValuePair> resutl = null; if(ObjectUtils.isNotEmpty(result)){ resutl = result.getBody(); } return resutl; }
public List<NameValuePair> tmpPermission(ThirdsysFuncpDTO thirdsysFuncpDTO){ List<NameValuePair> list = new ArrayList<NameValuePair>(); list.add(new BasicNameValuePair("1", "djfk")); list.add(new BasicNameValuePair("2", "123")); list.add(new BasicNameValuePair("3", "qweqwe")); list.add(new BasicNameValuePair("4", "3asfd")); list.add(new BasicNameValuePair("5", "你好")); return list; }
@RequestMapping(value = "/UserThirdsysfunc/test", method = RequestMethod.POST) public @ResponseBody List<NameValuePair> getDataset(HttpServletRequest request, HttpServletResponse response, @RequestBody ThirdsysFuncpDTO thirdsysFuncpDTO) { return userThirdsysfuncManager.tmpPermission(thirdsysFuncpDTO); }
另外一种:
public JSONArray getRateQueryController(Integer unitinfoId, Integer rmtypeId, Integer ratedefId, Integer setcurrencyId, String startdtString, String enddtString, Integer memberId, Integer tmnlplfid) { RestTemplate restTemplate = new RestTemplate(); String str = restTemplate.getForObject(result_url+"?unitinfoId=" + unitinfoId + "&rmtypeId=" + rmtypeId + "&ratedefId=" + ratedefId + "&setcurrencyId=" + setcurrencyId + "&startdtString=" + startdtString + "&enddtString=" + enddtString + "&memberId=" + memberId + "&tmnlplfid=" + tmnlplfid, String.class); JSONArray jsonarray = JSONArray.fromObject(str); return jsonarray; };
public List<ResultRatedtl> getRateQueryResult(Integer unitinfoId, Integer rmtypeId, Integer ratedefId, Integer setcurrencyId, String startdtString, String enddtString, Integer memberId, Integer tmnlplfid) { JSONArray jsonarray = rateManager.getRateQueryController(unitinfoId, rmtypeId, ratedefId, setcurrencyId, startdtString, enddtString, memberId, tmnlplfid); List<ResultRatedtl> list = (List<ResultRatedtl>) JSONArray.toCollection(jsonarray, ResultRatedtl.class); return list; }
@RequestMapping(value = "/RateQuery/result", method = RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE) public @ResponseBody List<ResultRatedtl> getRatedefQueryResult(OrderParamDTO orderParamDTO) { List<ResultRatedtl> list = rateQueryManager.getRatedefQueryResult(orderParamDTO); return list; }