接口传送集合数据备份

    //请求路径  
    String url = address+"/priceFreightpriceController.do?outGetMaplist&chargeableWeight="+weight; //url=url+"&data="+jsonString; Gson gson = new Gson(); //List转String String listAsString = gson.toJson(returnList); CloseableHttpClient httpclient = HttpClients.createDefault(); HttpPost method = new HttpPost(url); //参数 JSONObject jobsql = new JSONObject(); jobsql.put("data",listAsString); String body = jobsql.toString(); StringEntity entity = new StringEntity(body, Charset.forName("UTF-8")); method.setEntity(entity); method.setHeader("User-Agent", "Apipost client Runtime/+https://www.apipost.cn/"); method.setHeader("Content-Type", "application/json"); HttpResponse response = httpclient.execute(method); //返回数据 String content = EntityUtils.toString(response.getEntity(), "UTF-8"); //String转list returnList = gson.fromJson(content, List.class); // System.out.println("aaa ==>>" + returnList);
    //调用
    @RequestMapping(params = "outGetMaplist")
    @ResponseBody
    public List<Map<String, Object>> outGetMaplist(@RequestBody JSONObject json, String data, String chargeableWeight){
        List<Map<String, Object>> list = new ArrayList<>();
        try{
            String data1 = json.getString("data");

            Gson gson = new Gson();
       //将String 转 LIst List
<Map<String, Object>> oldList = gson.fromJson(data1, List.class);
       //处理后返回集合 list
= getMaplist(oldList,chargeableWeight); //System.out.println(list); }catch(Exception e){ e.printStackTrace(); }
// 返回响应 return list; }

 

posted @ 2024-02-08 08:32  薛柏梁  阅读(3)  评论(0编辑  收藏  举报