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


  • 相关阅读:
    记一次文件上传报错解决过程The temporary upload location is not vali
    Redis反序列化LocalDateTime时报错
    Redis连接池Lettuce Jedis 区别
    Java获取时间打印到控制台
    Java多线程之volatile关键字
    Java多线程之Future,有返回值的线程
    ccf集合竞价
    增广路径求解最大流
    2016年9月ccf
    hash表的建立和查找
  • 原文地址:https://www.cnblogs.com/yxj808/p/13297890.html
Copyright © 2011-2022 走看看