restTemplate 返回List方式小结

HTTP GET(一)方式:

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;
    }

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

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

HTTP POST方式:

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;
    }

 

posted @ 2019-12-09 09:48  Shapley  阅读(10010)  评论(0编辑  收藏  举报