restTemplate 返回List方式小结

HTTP GET(一)方式:

restTemplate 返回List方式小结
public List<UtMerFeedback> findUtMerFeedbackListByMerid(String merid) {
        HttpHeaders headers = new HttpHeaders();
        headers.set("Accept", "application/json");
        HttpEntity entity = new HttpEntity(headers);
        Map<String, String> params = new HashMap<String, String>();
        params.put("merid", merid);
        String url = restServerAdd + "/merchants/findUtMerFeedbackListByMerid?merid="+merid;
        ParameterizedTypeReference<List<UtMerFeedback>> responseType = new ParameterizedTypeReference<List<UtMerFeedback>>() {};
        ResponseEntity<List<UtMerFeedback>> resp = restTemplate.exchange(url, HttpMethod.GET, entity, responseType,params);
        List<UtMerFeedback> list = resp.getBody();
        return list;
    }
restTemplate 返回List方式小结

HTTP GET(二)方式(查询结果不能编辑):

    public List<UtProjectOnly> getProjectList() {
        String url = restServerAdd + "/project/getProjectList";
        UtProjectOnly[] model = restTemplate.getForObject(url, UtProjectOnly[].class);
        return Arrays.asList(model);
    }

HTTP POST方式:

restTemplate 返回List方式小结
public List<UtProjectAtt> getProjectFileList(String pid) {
        String url = restServerAdd + "/project/getProjectFileList";
        MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<String, Object>();
        paramMap.add("pid", pid);
        HttpHeaders headers = new HttpHeaders();
        HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<MultiValueMap<String, Object>>(paramMap, headers);
        ResponseEntity<List<UtProjectAtt>> response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, new ParameterizedTypeReference<List<UtProjectAtt>>() {
        });
        List<UtProjectAtt> checks = response.getBody();
        return checks;
    }
restTemplate 返回List方式小结
上一篇:使用Spring RestTemplate 发送 List,上传多个文件


下一篇:springcloud-基于RestTemplate的服务调用