后端服务A远程调用服务B传递List<String>参数

服务B的接收接口

   @ApiOperation("根据教研室corpIdList查询教研室的成员数量")
    @PostMapping("/user/count")
    public AjaxResult getRoomUserCount(@RequestBody List<String> corpIdList) {
        List<JxClassroomUserCountVo> voList = classroomService.getRoomUserCount(corpIdList);
        return AjaxResult.success(voList);
    }

服务A调用方

List<String> corpIdList = jxClassroomList.stream().map(JxClassroom::getCorpId).collect(Collectors.toList());
String jsonString = JSONObject.toJSONString(corpIdList);
String info = HttpUtil.sendPost(DataUrl + "/room/user/count", jsonString);

这个是封装好的发送post请求方法

/**
     * 发送HttpPost请求,参数为json字符串
     *
     * @param url     请求地址
     * @param jsonStr json字符串
     * @return
     */
    public static String sendPost(String url, String jsonStr) {
        CloseableHttpClient httpclient = getBuilder().build();
        HttpPost httpPost = new HttpPost(url);
        String result = null;
        try {
            StringEntity stringEntity = new StringEntity(jsonStr, Consts.UTF_8);
            stringEntity.setContentType("application/json");
            httpPost.setEntity(stringEntity);
            CloseableHttpResponse httpResponse = httpclient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
            result = EntityUtils.toString(httpEntity);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;

    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值