zoukankan      html  css  js  c++  java
  • 用Resttemple从数据接口中取出数据

    用RestTemple是需要对应的配置文件的,这里就不放了
    @Autowired
    private RestTemplate restTemplate;

    public JSONObject handle(String url){
    System.out.println("调用数据接口");
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.add("Accept", "application/json");//请求头
    headers.add("appId", "6325b8c0548b64716c9091c44b4b0bb3");
    headers.add("userName", "yyzg");
    headers.add("passWord", "000000");
    MultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
    HttpEntity<MultiValueMap> request = new HttpEntity<MultiValueMap>(map, headers);
    JSONObject response = restTemplate.postForEntity(url, request, JSONObject.class).getBody();
    System.out.println(response);
    return response;
    }

    如果要做分页

    @Autowired
    private RestTemplate restTemplate;
    public JSONObject handle(String url,Integer pageIndex,Integer pageSize){
    System.out.println("调用数据接口");
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.add("Accept", "application/json");//请求头
    headers.add("appId", "6325b8c0548b64716c9091c44b4b0bb3");
    headers.add("userName", "yyzg");
    headers.add("passWord", "000000");
    JSONObject json=new JSONObject();
    json.put("pageIndex",pageIndex);
    json.put("pageSize",pageSize);
    HttpEntity<String> entity = new HttpEntity<>(JSONObject.toJSONString(json),headers);
    JSONObject response= restTemplate.postForObject(url, entity,JSONObject.class);

    return response;
    }


  • 相关阅读:
    fescar中文官网
    mybatis 中的 update 返回值你真的明白吗
    数据库读写分离搭建
    git 回退各种场景操作
    听说noip2015有幻方
    noi2015的回忆和教训
    bzoj4026
    bzoj4127
    bzoj2119
    关于fft的一点总结
  • 原文地址:https://www.cnblogs.com/yxj808/p/13297890.html
Copyright © 2011-2022 走看看