2
我必須編寫一個代碼,它從url.com/info/{CODE}獲取特定信息(並非全部),並使用json將其顯示在服務器中。
這是我的代碼到現在爲止:使用Httpclient獲取數據並使用JSON顯示
一個類來獲取信息
@RequestMapping("/info")
public class Controller {
public void httpGET() throws ClientProtocolException, IOException {
String url = "Getfromhere.com/";
CloseableHttpClient client = HttpClients.createDefault();
HttpGet request = new HttpGet(url);
CloseableHttpResponse response = client.execute(request);
}
和一類應返回根據用戶在URL中插入的代碼數據
@RequestMapping(value = "/{iataCode}", method = RequestMethod.GET)
@ResponseBody
public CloseableHttpResponse generate(@PathVariable String iataCode) {
;
return response;
}
我該如何實現json的返回?
多謝,我會盡力糾正代碼,我會回來,如果我有任何更多的問題 – langStrife
它的工作,我設法運行,我需要的方式,程序。 – langStrife