美文网首页
Springboot RestTemplate-- 用更优雅的方

Springboot RestTemplate-- 用更优雅的方

作者: 日落_3d9f | 来源:发表于2020-04-01 10:55 被阅读0次

    更多,参看:案例,下面代码是我根据案例编写的一个请求:

        public static String postObject(){
            RestTemplate restTemplate = new RestTemplate();
            String url = "http://222.222.222.222:222/dcmp/ws/manuInfo";
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
    
            JSONObject rspObj = new JSONObject();
            rspObj.put("creditcode_nbr", "913100001331360409G");
            rspObj.put("dataupdate_nbr", "12345678");
            rspObj.put("warehousearea_nbr", "913100001331360409G.01");
            rspObj.put("start_date", "20200401");
            ArrayList<Map> inventoryInfo_list = new ArrayList<>();
            Map inventoryInfo_list_item = new HashMap();
            inventoryInfo_list_item.put("whpname_nbr","1049");
            inventoryInfo_list_item.put("number","2");
            inventoryInfo_list_item.put("unit","K");
            inventoryInfo_list.add(inventoryInfo_list_item);
            rspObj.put("inventoryInfo_list", inventoryInfo_list);
    
            HttpEntity<JSONObject> request = new HttpEntity<>(rspObj, headers);
            ResponseEntity<String> response = restTemplate.postForEntity( url, request , String.class );
            return response.getBody();
        }
    

    相关文章

      网友评论

          本文标题:Springboot RestTemplate-- 用更优雅的方

          本文链接:https://www.haomeiwen.com/subject/szsouhtx.html