AnNong。
2019-10-21 14:37
采纳率: 33.3%
浏览 1.1k
已采纳

restTemplate返回list接收不到

如下,我要返回这个list,但是客户端接收不到

@RequestMapping(value = "getHouseList",method = RequestMethod.POST)
    @ResponseBody
    public List getHouseList(HttpServletRequest request) {
        //封装结果集
        HashMap<Object, Object> resultMap = Maps.newHashMap();
        ArrayList<Object> list = Lists.newArrayList();
        PageInfo<Project> pageInfo = new PageInfo<Project>();
        pageInfo.setPageSize(Integer.MAX_VALUE);
        pageInfo = this.projectService.list(pageInfo);
        List<Project> projectList = pageInfo.getResult();
        if(projectList!=null&&projectList.size()!=0){
            for (Project project : projectList) {
                List<String> builds = this.houseService.builds(project.getId());
                resultMap.put(project.getId(),builds);
            }
        }
        list.add(projectList);
        list.add(resultMap);
        return list;
    }

客户端请求如下: 返回的size=0 这是为什么?

 HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
        headers.setContentType(type);
        headers.add("Accept", MediaType.APPLICATION_JSON.toString());
        HttpEntity<String> formEntity = new HttpEntity<String>( headers);
        List list = restTemplate.postForObject(url, formEntity, List.class);
        System.out.println(list.size());

3条回答 默认 最新

相关推荐 更多相似问题