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


  • 相关阅读:
    尘误解
    了解了解你自己的话zookeeper(从那时起,纠正了一些说法在线)
    HDU 5055 Bob and math problem(结构体)
    Linux通过编辑器vi使用介绍
    OCP-1Z0-051-名称解析-文章32称号
    刘强东:解密京东10甘蔗理论
    Android结构分析Android智能指针(两)
    hbase ganglia监控配置
    第一个位和一个真正的项目件
    Html5 の 微信飞机大战
  • 原文地址:https://www.cnblogs.com/yxj808/p/13297890.html
Copyright © 2011-2022 走看看