如何在一个项目调另一个项目中的接口?

如何在一个项目调另一个项目中的接口?

第一种方法:

1,pom.xml中增加依赖:

 <dependency>
            <groupId>com.konghq</groupId>
            <artifactId>unirest-java</artifactId>
            <version>2.3.17</version>
        </dependency>

2,//调另一个项目导入学生数接口: 查询提交报告学生数,查询实验报告数量 if (!CollectionUtils.isEmpty(courseIdList)) { String courseIdString = StringUtils.join(courseIdList.toArray(), ","); String url = "http://" + LOCAL_URL + "/student/queryStuCountByCourseIds?courseIds=" + courseIdString+"&timeIdentify="+timeIdentify; **HttpResponse<String> post = Unirest.post(url).asString(); JSONObject dataJsonObject = JSONObject.parseObject(post.getBody());** JSONObject data= (JSONObject) dataJsonObject.get("data"); importStudentsNumber= (Integer) data.get("importStudentsNumber"); reportStudentsNumber= (Integer) data.get("reportStudentsNumber"); experimentReportNumber= (Integer) data.get("experimentReportNumber"); }

第二种方法:
使用httpClient(百度一下就出来了,也是先在pom文件中引入依赖,然后再写代码调用)

猜你喜欢

转载自blog.csdn.net/weixin_43228497/article/details/115857090