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


  • 相关阅读:
    System.Web.Mvc.RoutePrefixAttribute.cs
    HTML5: 实现调用系统拍照或者选择照片并预览
    System.DateTime.cs
    System.Math.cs
    System.Web.UI.WebControls.FileUpload.cs
    系统过程分析
    java实现数字黑洞
    java实现数字黑洞
    java实现数字黑洞
    java实现数字黑洞
  • 原文地址:https://www.cnblogs.com/yxj808/p/13297890.html
Copyright © 2020-2023  润新知