1.在pom.xml引入包
<dependency> <groupId>commons-httpclient</groupId> <artifactId>commons-httpclient</artifactId> <version>3.1</version> </dependency>
2.
@GetMapping("/baseList") @ResponseBody public List<Base> getBaseList() throws IOException { org.apache.commons.httpclient.HttpClient httpClient = new org.apache.commons.httpclient.HttpClient(); GetMethod getMethod = new GetMethod("接口地址"); //getToken(),调用获取token的方法 String authorization = getToken(); getMethod.addRequestHeader("Authorization",authorization); httpClient.executeMethod(getMethod); String back1 = getMethod.getResponseBodyAsString(); JSONObject object1 = JSON.parseObject(back1); String data = object1.getObject("data",String.class); List<Base> list = JSONArray.parseArray(data,Base.class); return list; }